Why Prevent Gestures
By default, a touch-enabled device allows a user to pan and zoom a web app. But sometimes this is not something that’s appropriate for an app.
Here’s how to prevent these gestures from messing up your web app:
Prevent Panning and Zooming
1 | html, body { |
This will prevent single-finger panning, and two-finger pinch zooming on all elements. This does not, however, disable the double-tap to zoom feature. Disabling double-tap zoom requires a different method.
Prevent Double-Tap Zoom
This zoom effect can be annoying, as clicking a button twice can invoke it.
In order to prevent it, place a listener for dblclick
on the element being clicked:
1 | // gobble up the 'dblclick' event |
Another option to disable double-tap to zoom is with CSS:
1 | /* disable double-tap to zoom */ |
This disables double-tap to zoom, but it enables panning and pinch zoom.