-
-
Save pwfisher/3186864 to your computer and use it in GitHub Desktop.
A jQuery plugin to selectively disable the iOS double-tap-to-zoom action on specific page elements (and have that generate two click events instead).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery no-double-tap-zoom plugin | |
// Triple-licensed: Public Domain, MIT and WTFPL license - share and enjoy! | |
(function($) { | |
var IS_IOS = /iphone|ipad/i.test(navigator.userAgent); | |
$.fn.nodoubletapzoom = function() { | |
if (IS_IOS) | |
$(this).bind('touchstart', function preventZoom(e) { | |
var now = (new Date().getTime()), | |
elapsed = now - (this._lastTouch || 0), | |
fingers = e.touches.length, | |
isDoubleTap = (fingers === 1 && elapsed < 500); | |
if (isDoubleTap) { e.preventDefault(); } | |
this._lastTouch = now; | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
e.timeStamp and e.originalEvent were not available for me and I didn't need to synthesize an event because we're using synthetic tap events already, to work around the browser delay on click events (due to double-click detection). So this is what I'm using. I've also refactored the logic for clarity.