Vue 页面弹出遮罩层的时候我想禁止页面滑动,遮罩层结束了页面可以滑动,我现在禁止滑动了但是解除不了了 怎么解决呢

Vue 页面弹出遮罩层的时候我想禁止页面滑动,遮罩层结束了页面可以滑动,我现在禁止滑动了但是解除不了了 怎么解决呢
点击时间出现遮罩

clipboard.png

clipboard.png

当出现时间选择的时候页面禁止滑动(有效)

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

当选择完时间的时候 页面应该可以再次滑动怎么解决呢? (无效)

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

怎么解决这个问题呢?

阅读 4.8k
2 个回答

function preDev(e){
e.preventDefault();
}
document.body.addEventListener('touchmove', preDev, {passive: false})
取消蔗罩时
document.body.removeEventListener('touchmove', preDev, {passive: false})试试

搞一个类就可以了,.hidden {heigh:100%; overflow:hidden}弹窗出现的时候把这个类加到body上,弹窗隐藏的时候去掉就可以了……

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题