Skip to content

Instantly share code, notes, and snippets.

@pwfisher
Forked from johan/jquery.nodoubletapzoom.js
Created July 27, 2012 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwfisher/3186864 to your computer and use it in GitHub Desktop.
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).
// 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);
@pwfisher
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment