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

IOS 10 Safari手机浏览器禁止缩放 #31

Open
incuisting opened this issue Sep 12, 2017 · 2 comments
Open

IOS 10 Safari手机浏览器禁止缩放 #31

incuisting opened this issue Sep 12, 2017 · 2 comments

Comments

@incuisting
Copy link
Owner

和往常一样,给移动端页面加了禁止缩放的meta标签

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

在手机上测试一下效果。。。
完全不OK!!!meta一点作用没有
Google之后得出结论IOS10的Safari 不再识别meta viewport。。

emmmmmm。。。。

那么就只能用js来HACK了

禁用双指缩放:

document.documentElement.addEventListener('touchstart', function (event) {
  if (event.touches.length > 1) {
    event.preventDefault();
  }
}, false);

禁用手指双击缩放:

var lastTouchEnd = 0;
document.documentElement.addEventListener('touchend', function (event) {
  var now = Date.now();
  if (now - lastTouchEnd <= 300) {
    event.preventDefault();
  }
  lastTouchEnd = now;
}, false);

不过设置了viewport之后 是禁止了手指双击缩放的。所以目前最理想的方案是,viewport照常设置,js上加上禁用双指缩放的代码片段。就完全OK了。

@Pakepeng
Copy link

偶尔点击还会有不起作用的时候,具体原因不太清楚

@PLQin
Copy link

PLQin commented Sep 7, 2020

还是有一丢丢瑕疵,主要是双指放大还是有bug,双指同时按在屏幕上能够避免放大,但是当手指先后放在屏幕上进行放大操作时,不能避免 ;

如果有兄嘚找到了更好的方案,请艾特一下我

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants