简体   繁体   English

React JS 如何禁用缩放

[英]React JS How to disable zoom

Im building a web app and I want to disable the zoom with 2 fingers.我正在构建一个 web 应用程序,我想禁用 2 根手指的缩放功能。 I have tried this我试过这个

meta name="viewport" content=" width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"

but is not working.但不工作。 The app will run on tablets.该应用程序将在平板电脑上运行。

Thank you !谢谢 !

With the React-Helmet you can put your metadata in the render-function of your Component like this:使用 React-Helmet,您可以将元数据放入组件的渲染函数中,如下所示:

render(){ 
    return <div>
        <Helmet>
              <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
        </Helmet>
        [...]
    </div>
}

Look at the Helmet documentation for further information.查看Helmet 文档以获取更多信息。

Disables iOS pinch-zoom禁用 iOS 双指缩放

window.addEventListener(
  "touchmove",
  function (event) {
    if (event.scale !== 1) {
      event.preventDefault();
      event.stopImmediatePropagation();
    }
  },
  { passive: false }
);

Tested on iOS 15.3 in Safari and Brave.在 Safari 和 Brave 中测试 iOS 15.3。

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

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