diff --git a/boards/static/js/image.js b/boards/static/js/image.js --- a/boards/static/js/image.js +++ b/boards/static/js/image.js @@ -83,16 +83,21 @@ PopupImageViewer.prototype.view = functi var win_w = win.width(); var win_h = win.height(); - //new image size + + // New image size + var w_scale = 1; + var h_scale = 1; if (img_w > win_w) { - img_h = img_h * (win_w/img_w) - margin; - img_w = win_w - margin; + w_scale = img_w / (win_w - margin); } if (img_h > win_h) { - img_w = img_w * (win_h/img_h) - margin; - img_h = win_h - margin; + h_scale = img_h / (win_h - margin); } + var scale = Math.max(w_scale, h_scale) + img_w = img_w / scale; + img_h = img_h / scale; + var img_pv = new Image(); var newImage = $(img_pv); newImage.addClass('img-full') @@ -107,19 +112,22 @@ PopupImageViewer.prototype.view = functi }) //scaling preview .mousewheel(function(event, delta) { - var cx = event.originalEvent.clientX, - cy = event.originalEvent.clientY, - i_w = parseFloat(newImage.width()), - i_h = parseFloat(newImage.height()), - newIW = i_w * (delta > 0 ? 1.25 : 0.8), - newIH = i_h * (delta > 0 ? 1.25 : 0.8); + var cx = event.originalEvent.clientX; + var cy = event.originalEvent.clientY; + + var i_w = parseFloat(newImage.width()); + var i_h = parseFloat(newImage.height()); + + var newIW = i_w * (delta > 0 ? 1.25 : 0.8); + var newIH = i_h * (delta > 0 ? 1.25 : 0.8); newImage.width(newIW); newImage.height(newIH); - //set position + // Set position + var oldPosition = newImage.position(); newImage.css({ - left: parseInt(cx - (newIW/i_w) * (cx - parseInt($(img_pv).position().left, 10)), 10), - top: parseInt(cy - (newIH/i_h) * (cy - parseInt($(img_pv).position().top, 10)), 10) + left: parseInt(cx - (newIW/i_w) * (cx - parseInt(oldPosition.left, 10)), 10), + top: parseInt(cy - (newIH/i_h) * (cy - parseInt(oldPosition.top, 10)), 10) }); return false;