美文网首页
禁止ios浏览器页面滚动的橡皮筋效果

禁止ios浏览器页面滚动的橡皮筋效果

作者: 兮木兮木 | 来源:发表于2020-04-08 12:43 被阅读0次

问题:在做手机端,通过拖拽调整某个div大小时,拖拽引起了整体页面的弹动

  • 方法一:通过css设置body宽高

    html, body {
      width: 100%;
        height: 100%;
        overflow: hidden
    }
    
  • 方法二:阻止bodytouchmove事件
    单纯解决橡皮筋效果,可以将bodytouchmove事件禁止,可以替代第一种方法

    document.body.addEventListener('touchmove', function (e) {
            e.preventDefault() // 阻止默认的处理方式(阻止下拉滑动的效果)
        }, {passive: false}) // passive 参数不能省略,用来兼容ios和android
    

相关文章

网友评论

      本文标题:禁止ios浏览器页面滚动的橡皮筋效果

      本文链接:https://www.haomeiwen.com/subject/fattmhtx.html