禁止页面滚动:body{style="overflow:hidden;"}
可以实现大部分超出页面禁止滚动,可并非兼容所有移动手机。
document.body.addEventListener('touchmove',function(event){ event.preventDefault(); },false);
PC端禁止键盘上下键
var move=function(e){ e.preventDefault && e.preventDefault(); e.returnValue=false; e.stopPropagation && e.stopPropagation(); return false; } var keyFunc=function(e){ if(37<=e.keyCode && e.keyCode<=40){ return move(e); } } document.body.onkeydown=keyFunc;
在iPhone中使用body{style="overflow:hidden;"} 是无效的,对于一个页面使用覆盖层,并且禁止底层滚动 可以采用禁止touch事件