方法一:
在点击事件(弹出弹框)时,添加
document.querySelector('body').setAttribute('style', 'position:fixed;left: 0px;right: 0px;overflow: hidden;')
在隐藏弹框时
document.querySelector('body').removeAttribute('style')
方法二:
在点击事件(弹出弹框)时,添加
let custom =function(e){e.preventDefault();};
document.body.style.overflow='hidden';
document.addEventListener("touchmove", custom,false);//禁止页面滑动
在隐藏弹框方法中,添加
let custom=function(e){e.preventDefault();};
document.body.style.overflow='auto';//出现滚动条
document.removeEventListener("touchmove", custom,false);
网友评论