简体   繁体   English

iOS Safari - 禁用捏缩放选项

[英]iOS Safari - disable pinch to zoom option

I have an issue with zooming.我有缩放问题。 I want to block pinch to zoom in Mobile Safari on HTML elements.我想阻止捏合以放大 HTML 元素上的 Mobile Safari。 I use script to prevent default behavior of browser and it is working fine for normal pinching, but when I start scroll with one finger and later add second and pinch Safari still zooming the page...我使用脚本来防止浏览器的默认行为,它对于正常的捏合工作正常,但是当我用一根手指开始滚动并稍后添加第二个并捏住 Safari 时,它仍在缩放页面...

Has anyone any idea how can I block this zooming?有谁知道如何阻止这种缩放?

I'am creating mobile game using canvas and use HTML for message windows so please don't write that it is a bad idea to block zooming for accessibility reasons.我正在使用画布创建手机游戏,并在消息窗口中使用 HTML,因此请不要写出出于可访问性原因阻止缩放是一个坏主意。

Code to prevent zooming:防止缩放的代码:

document.addEventListener("touchmove", function(event) {
  event = event.originalEvent || event;

  if(event.touches.length > 1 || event.scale > 1) {
    event.preventDefault();
  }
}, false);

UPDATE:更新:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

This meta tag doesn't work because Apple disable it in Mobile Safari since iOS 10 up to accessibility reasons此元标记不起作用,因为 Apple 自 iOS 10 起因可访问性原因在 Mobile Safari 中禁用它

can you test it?你能测试一下吗?

document.documentElement.addEventListener('touchmove', function (event) {
    event.preventDefault();
}, false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM