Skip to content

Commit

Permalink
Merge pull request #46 from reachdevelopers/master
Browse files Browse the repository at this point in the history
Mobile only offset touch point to be at the bottom instead of the center
  • Loading branch information
thdoan authored Apr 16, 2018
2 parents 358579b + 0dadb58 commit 436c661
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions dist/js/jquery.magnify.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'finalHeight': null,
'magnifiedWidth': null,
'magnifiedHeight': null,
'touchBottom': true,
'limitBounds': false,
'mobileCloseEvent': 'touchstart',
'afterLoad': function(){}
Expand Down Expand Up @@ -159,8 +160,35 @@
//
// We deduct the positions of .magnify from the mouse or touch positions relative to
// the document to get the mouse or touch positions relative to the container.
nX = (e.pageX || e.originalEvent.touches[0].pageX) - oContainerOffset['left'],
nY = (e.pageY || e.originalEvent.touches[0].pageY) - oContainerOffset['top'];

// Mobile only offset touch point to be at the bottom not on the center
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
if(isMobile.any() && oOptions.touchBottom === true) {
nX = (e.pageX || e.originalEvent.touches[0].pageX) - oContainerOffset['left'],
nY = ((e.pageY || e.originalEvent.touches[0].pageY) - oContainerOffset['top']) -90;
} else {
nX = (e.pageX || e.originalEvent.touches[0].pageX) - oContainerOffset['left'],
nY = (e.pageY || e.originalEvent.touches[0].pageY) - oContainerOffset['top'];
}
// Toggle magnifying lens
if (!$lens.is(':animated')) {
if (nX>nBoundX && nX<nImageWidth-nBoundX && nY>nBoundY && nY<nImageHeight-nBoundY) {
Expand Down

0 comments on commit 436c661

Please sign in to comment.