Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

手机浏览器不设置overflow会导致自动缩放 #20

Open
leopen-hu opened this issue Feb 21, 2021 · 0 comments
Open

手机浏览器不设置overflow会导致自动缩放 #20

leopen-hu opened this issue Feb 21, 2021 · 0 comments

Comments

@leopen-hu
Copy link
Owner

leopen-hu commented Feb 21, 2021

当内容长度超过屏幕宽度时,如果不设置overflow,那么浏览器页面会按比例(最长元素宽度/设备宽度)缩放,引发显示异常的问题。
复现代码如下:

<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, width=device-width" />
  </head>
  <style>
    * {
      padding: 0;
      margin: 0;
    }
    .overflow {
      overflow: auto;
    }
  </style>
  <script>
    function changeOverflow() {
      console.log('1111111111111111111');
      const ele = document.getElementById('testDiv');
      const overflow = ele.className;

      if (overflow) {
        ele.className = ''
      } else {
        ele.className = 'overflow'
      }
    }
  </script>
  <body>
    <button onclick="changeOverflow()">changeOverflow</button>
    <p style="width: 100vw; background-color: black;">fff</p>
    <div id="testDiv" class="overflow">fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff</div>
  </body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant