【问题标题】:Unable to remove zoom in and zoom out in my flutter web无法在我的颤动网络中删除放大和缩小
【发布时间】:2021-08-10 19:31:45
【问题描述】:

我想禁用 Flutter Web 的放大功能。我已经尝试过这些事情:-

1) 将以下代码添加到 index.html 文件中

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

但它给了我以下警告并且没有禁用缩放。

WARNING: found an existing <meta name="viewport"> tag. Flutter Web uses its own viewport configuration for better compatibility with Flutter. This tag will be replaced.

2) 在 index.html 的 body 标签中添加以下代码:-

<script>
  document.addEventListener('wheel', function(e) {
    e.ctrlKey && e.preventDefault();
  }, {
    passive: false,
  });
</script>

它禁用了使用 ctrl 和鼠标滚动进行缩放,但禁用了使用 ctrl + 进行缩放和使用 ctrl - 进行缩小的缩放。

所以,你能告诉我如何在所有平台(即桌面、android 和 ios)中禁用我的网页的放大和缩小。

【问题讨论】:

    标签: javascript html flutter zooming flutter-web


    【解决方案1】:

    我通过在 index.html 文件的正文中添加以下 javascript 代码找到了禁用移动和桌面缩放的答案:-

    <script>
      document.addEventListener('wheel', function(e) {
        e.ctrlKey && e.preventDefault();
      }, {
        passive: false,
      });
    </script>
    <script>
      window.addEventListener('keydown', function(e) {
        if (event.metaKey || event.ctrlKey) {
          switch (event.key) {
            case '=':
            case '-':
              event.preventDefault();
              break;
          }
        }
      });
    </script>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-03
      • 1970-01-01
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-28
      相关资源
      最近更新 更多