vue中禁止遮罩底层页面滑动

2020-08-04  本文已影响0人  jing_bao

方法一:
在点击事件(弹出弹框)时,添加

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);
上一篇 下一篇

猜你喜欢

热点阅读