Google Chrome Pinch-to-zoom prevention

孤者浪人 提交于 2019-12-10 12:37:19

问题


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:

  1. going to chrome://flags
  2. click enable "Enable viewport meta tag"

Programmatic approach

(as suggested in comments above):

  1. Listen to touchmove events
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!