移动端阻止浏览器页面缩放

// 在head标签加上
 <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no"/>

// 如果在 safari 内核没有用,可以加上以下js
// 阻止safari内核的浏览器点击缩放
  window.onload = function() {
      let lastTouchEnd = 0;
      document.addEventListener('touchstart', function(event) {
          if (event.touches.length > 1) {
              event.preventDefault();
          }
      });
      document.addEventListener('touchend', function(event) {
        let now = (new Date()).getTime();
          if (now - lastTouchEnd <= 300) {
              event.preventDefault();
          }
          lastTouchEnd = now;
      }, false);
      document.addEventListener('gesturestart', function(event) {
          event.preventDefault();
      });
      document.addEventListener('dblclick', function (event) {
          event.preventDefault();
    })
  }

 

posted @ 2021-05-20 15:06  秦笑  阅读(247)  评论(0编辑  收藏  举报