Skip to content

Instantly share code, notes, and snippets.

@johan
Created March 15, 2012 22:59
Show Gist options
  • Star 34 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save johan/2047491 to your computer and use it in GitHub Desktop.
Save johan/2047491 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 t2 = e.timeStamp
, t1 = $(this).data('lastTouch') || t2
, dt = t2 - t1
, fingers = e.originalEvent.touches.length;
$(this).data('lastTouch', t2);
if (!dt || dt > 500 || fingers > 1) return; // not double-tap
e.preventDefault(); // double tap - prevent the zoom
// also synthesize click events we just swallowed up
$(this).trigger('click').trigger('click');
});
};
})(jQuery);
@alsatian
Copy link

alsatian commented Aug 6, 2022

@evelinamikhailova87 You made my day, nothing else worked, the 'dblclick' one does magic! No more double tap zoom on iOS 15 (iPadOS 15) for me! Thank you!!

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