##// END OF EJS Templates
Fixed image popup scale
neko259 -
r1351:21f71300 default
parent child Browse files
Show More
@@ -83,16 +83,21 b' PopupImageViewer.prototype.view = functi'
83
83
84 var win_w = win.width();
84 var win_w = win.width();
85 var win_h = win.height();
85 var win_h = win.height();
86 //new image size
86
87 // New image size
88 var w_scale = 1;
89 var h_scale = 1;
87 if (img_w > win_w) {
90 if (img_w > win_w) {
88 img_h = img_h * (win_w/img_w) - margin;
91 w_scale = img_w / (win_w - margin);
89 img_w = win_w - margin;
90 }
92 }
91 if (img_h > win_h) {
93 if (img_h > win_h) {
92 img_w = img_w * (win_h/img_h) - margin;
94 h_scale = img_h / (win_h - margin);
93 img_h = win_h - margin;
94 }
95 }
95
96
97 var scale = Math.max(w_scale, h_scale)
98 img_w = img_w / scale;
99 img_h = img_h / scale;
100
96 var img_pv = new Image();
101 var img_pv = new Image();
97 var newImage = $(img_pv);
102 var newImage = $(img_pv);
98 newImage.addClass('img-full')
103 newImage.addClass('img-full')
@@ -107,19 +112,22 b' PopupImageViewer.prototype.view = functi'
107 })
112 })
108 //scaling preview
113 //scaling preview
109 .mousewheel(function(event, delta) {
114 .mousewheel(function(event, delta) {
110 var cx = event.originalEvent.clientX,
115 var cx = event.originalEvent.clientX;
111 cy = event.originalEvent.clientY,
116 var cy = event.originalEvent.clientY;
112 i_w = parseFloat(newImage.width()),
117
113 i_h = parseFloat(newImage.height()),
118 var i_w = parseFloat(newImage.width());
114 newIW = i_w * (delta > 0 ? 1.25 : 0.8),
119 var i_h = parseFloat(newImage.height());
115 newIH = i_h * (delta > 0 ? 1.25 : 0.8);
120
121 var newIW = i_w * (delta > 0 ? 1.25 : 0.8);
122 var newIH = i_h * (delta > 0 ? 1.25 : 0.8);
116
123
117 newImage.width(newIW);
124 newImage.width(newIW);
118 newImage.height(newIH);
125 newImage.height(newIH);
119 //set position
126 // Set position
127 var oldPosition = newImage.position();
120 newImage.css({
128 newImage.css({
121 left: parseInt(cx - (newIW/i_w) * (cx - parseInt($(img_pv).position().left, 10)), 10),
129 left: parseInt(cx - (newIW/i_w) * (cx - parseInt(oldPosition.left, 10)), 10),
122 top: parseInt(cy - (newIH/i_h) * (cy - parseInt($(img_pv).position().top, 10)), 10)
130 top: parseInt(cy - (newIH/i_h) * (cy - parseInt(oldPosition.top, 10)), 10)
123 });
131 });
124
132
125 return false;
133 return false;
General Comments 0
You need to be logged in to leave comments. Login now