vue弹窗后如何禁止滚动

在有弹出框的页面中,弹出框出现时调用禁止滚动方法stopScroll()。

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

弹出框取消时调取允许滚动方法canScroll()即可恢复滚动。

/***允许滚动***/
 
  canScroll(){
 
    var mo=function(e){e.preventDefault();};
 
    document.body.style.overflow='';//出现滚动条
 
    document.removeEventListener("touchmove",mo,false);
 }

 

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容