Skip to content

Commit 436c661

Browse files
authored
Merge pull request #46 from reachdevelopers/master
Mobile only offset touch point to be at the bottom instead of the center
2 parents 358579b + 0dadb58 commit 436c661

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

dist/js/jquery.magnify.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'finalHeight': null,
1818
'magnifiedWidth': null,
1919
'magnifiedHeight': null,
20+
'touchBottom': true,
2021
'limitBounds': false,
2122
'mobileCloseEvent': 'touchstart',
2223
'afterLoad': function(){}
@@ -159,8 +160,35 @@
159160
//
160161
// We deduct the positions of .magnify from the mouse or touch positions relative to
161162
// the document to get the mouse or touch positions relative to the container.
162-
nX = (e.pageX || e.originalEvent.touches[0].pageX) - oContainerOffset['left'],
163-
nY = (e.pageY || e.originalEvent.touches[0].pageY) - oContainerOffset['top'];
163+
164+
// Mobile only offset touch point to be at the bottom not on the center
165+
var isMobile = {
166+
Android: function() {
167+
return navigator.userAgent.match(/Android/i);
168+
},
169+
BlackBerry: function() {
170+
return navigator.userAgent.match(/BlackBerry/i);
171+
},
172+
iOS: function() {
173+
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
174+
},
175+
Opera: function() {
176+
return navigator.userAgent.match(/Opera Mini/i);
177+
},
178+
Windows: function() {
179+
return navigator.userAgent.match(/IEMobile/i);
180+
},
181+
any: function() {
182+
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
183+
}
184+
};
185+
if(isMobile.any() && oOptions.touchBottom === true) {
186+
nX = (e.pageX || e.originalEvent.touches[0].pageX) - oContainerOffset['left'],
187+
nY = ((e.pageY || e.originalEvent.touches[0].pageY) - oContainerOffset['top']) -90;
188+
} else {
189+
nX = (e.pageX || e.originalEvent.touches[0].pageX) - oContainerOffset['left'],
190+
nY = (e.pageY || e.originalEvent.touches[0].pageY) - oContainerOffset['top'];
191+
}
164192
// Toggle magnifying lens
165193
if (!$lens.is(':animated')) {
166194
if (nX>nBoundX && nX<nImageWidth-nBoundX && nY>nBoundY && nY<nImageHeight-nBoundY) {

0 commit comments

Comments
 (0)