禁止弹层下页面滚动问题
1. 一般代码。
显示弹层时添加:
document.body.style.height = '100%';
document.body.style.overflow = 'hidden';
关闭弹层时添加:
document.body.style.height = '';
document.body.style.overflow = '';
2. 在IE中需要兼容。
显示弹层时添加:
document.documentElement.style.overflow = 'visible';
document.body.style.overflow = 'hidden';
关闭弹层时添加:
document.documentElement.style.overflow = 'auto';
document.body.style.overflow = 'auto';
3. 在移动端:
显示弹层时添加:
window.ontouchmove=function(e){ e.preventDefault && e.preventDefault(); e.returnValue=false; e.stopPropagation && e.stopPropagation(); return false; }
关闭弹层时添加:
window.ontouchmove=function(e){ e.preventDefault && e.preventDefault(); e.returnValue=true; e.stopPropagation && e.stopPropagation(); return true; }