移动端禁止页面滑动

今天碰到一个问题,用$(‘html’).css(“overflow”,“hidden”)禁止滚动在移动端竟然无效,不知道什么原因,所以又试了几个移动端禁止滑动方法,供参考。
方法一:(经测试有效)
禁止滑动

document.body.addEventListener('touchmove', function (e) {
	e.preventDefault()
}, {passive: false})

恢复滑动

document.body.addEventListener('touchmove', function (e) {
	window.event.returnValue = true
})

方法二:(经测试恢复滑动无效…)
禁止滑动

var fun=function(e){e.preventDefault();};
document.body.style.overflow='hidden';
document.addEventListener("touchmove",fun,{passive:false});//禁止页面滑动                    

用以下方法恢复滑动经测试无效…

var fun=function(e){e.preventDefault();};
document.body.style.overflow='';
document.removeEventListener("touchmove",fun,{passive:false});

方法三:(经测试使用此方法只能控制遮罩层不能滑动,遮罩层下面的内容仍然可以滑动,但恢复滑动是有效的)
禁止滑动

var fun=function(e){e.preventDefault();};
document.body.style.overflow='hidden';
document.addEventListener("touchmove",fun,false);//禁止页面滑动 

恢复滑动

var fun=function(e){e.preventDefault();};
document.body.style.overflow='';
document.removeEventListener("touchmove",fun,false); 

欢迎各位留言指点。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值