How to disable the scroll bar scrolling after the vue pop-up window

1. Add the following method to the page with the pop-up box. When the pop-up box appears, call the method stopScroll() to prohibit scrolling. To remove the pop-up box, just call the method canScroll() to allow scrolling. The code is as follows

methods : {
 
  //禁止滚动
 
  stopScroll(){
 
    var mo=function(e){e.preventDefault();};
 
    document.body.style.overflow='hidden';
 
    document.addEventListener("touchmove",mo,false);//禁止页面滑动
 
  },
 
  /***取消滑动限制***/
 
  canScroll(){
 
    var mo=function(e){e.preventDefault();};
 
    document.body.style.overflow='';//出现滚动条
 
    document.removeEventListener("touchmove",mo,false);
 
  }
 
}

2. In the global js, that is, main.js, set the global function and call it on the used pages. The code is as follows:

 

 
//弹出框禁止滑动
 
Vue.prototype.stopScroll = function () {
 
 var mo = function (e) { e.preventDefault() }
 
 document.body.style.overflow = 'hidden'
 
 document.addEventListener('touchmove', mo, false)// 禁止页面滑动
 
}
 
 
 
//弹出框可以滑动
 
Vue.prototype.canScroll = function () {
 
 var mo = function (e) {
 
  e.preventDefault()
 
 }
 
 document.body.style.overflow = ''// 出现滚动条
 
 document.removeEventListener('touchmove', mo, false)
 
}

 

3. The calling method of the specific page is as follows:

 //当需要禁止弹出框底部内容滑动时调用:

 this.stopScroll()

 //当需要页面恢复滑动功能时调用:

 this.canScroll()

Guess you like

Origin blog.csdn.net/qq_48294048/article/details/130555432