问题
I'm developing an app for Chrome on a Microsoft Surface Pro 2 running Windows 8.1. Recently, the Chromium team decided they wanted to add the pinch-to-zoom gesture in Chrome for Windows 8, which is all and good. They did not, however, add a flag to disable this behavior in Chrome's settings for those few of us that don't want pinch-to-zoom functionality.
Now I'm left trying to disable the browser's default behavior by other means. The first thing I tried was to add this meta-tag:
<meta name="viewport" content="width=device-width, initial-scale=1.5, maximum-scale=1.5, user-scalable=no" />
It had no effect. I've also been trying to use the hammer.js touch library to disable the behavior with limited success; pinching sufficiently fast enough still zooms the page.
Does anyone know of a effective way to disable the pinch-to-zoom behavior on Chrome for Windows 8.1?
回答1:
User-based approach:
Enable viewport meta tag support by:
- going to
chrome://flags
- click enable "Enable viewport meta tag"
Programmatic approach
(as suggested in comments above):
- Listen to
touchmove
events - call
preventDefault
on them if you detect two touches.
Note: Always preventing touchmove
would cause simple scroll to stop working
回答2:
Unfortunately it is not possible to completely block, it seems.
Matyas' solution will work great until you start using one finger to scroll, and then put another finger down and pinch to zoom.
Calling preventDefault in this case causes the warning: "Ignored attempt to cancel a touchmove event with cancelable=false, for example because scrolling is in progress and cannot be interrupted."
And the pinch to zoom is not blocked.
This appears to be a bug.
来源:https://stackoverflow.com/questions/22232735/google-chrome-pinch-to-zoom-prevention