Skip to content

Instantly share code, notes, and snippets.

@MaxLazar
Created October 10, 2014 11:41
Show Gist options
  • Save MaxLazar/713563dcb395cf499303 to your computer and use it in GitHub Desktop.
Save MaxLazar/713563dcb395cf499303 to your computer and use it in GitHub Desktop.
Disable double-tap “zoom” option in browser on touch devices
#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