// 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); |
This comment has been minimized.
This comment has been minimized.
Thanks for this! |
This comment has been minimized.
This comment has been minimized.
Thank you for this. I am using the presses of the button to call a function to increment a counter. I need the double taps to call my function twice. Might it be OK for me to call $(this).trigger('click').trigger('click'); twice in the section // also synthesize click events we just swallowed up. Thank you again. |
This comment has been minimized.
This comment has been minimized.
Thanks for your idea, I need to port this snippet to javascript. |
This comment has been minimized.
This comment has been minimized.
It dosnt seem to work? |
This comment has been minimized.
This comment has been minimized.
Works great, thanks a lot! |
This comment has been minimized.
This comment has been minimized.
Definitely save my day. thank you so much |
This comment has been minimized.
This comment has been minimized.
it is not working, i just check my iphone 7plus moblie.double tap to zoom still working on my mobile |
This comment has been minimized.
This comment has been minimized.
I think it should be |
This comment has been minimized.
Hey johan,
thanks for the snippet!
I'd just recommend adding a "return this;" to make it chainable.
--Thiemo