Created
October 10, 2014 11:41
-
-
Save MaxLazar/713563dcb395cf499303 to your computer and use it in GitHub Desktop.
Disable double-tap “zoom” option in browser on touch devices
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
#http://stackoverflow.com/questions/10614481/disable-double-tap-zoom-option-in-browser-on-touch-devices | |
(function($) { | |
$.fn.nodoubletapzoom = function() { | |
$(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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment