首先呢蔫,在觸發(fā)彈出浮層事件后添加下面代碼:
stopScroll(){
e.stopPropagation();
e.preventDefault();
},
showPop(){
document.body.addEventListener("touchmove", self.stopScroll, {passive: false });
document.body.style.overflow = 'hidden';
}
- passive參數(shù):
是否讓 阻止默認(rèn)行為(preventDefault()) 失效
當(dāng)觸發(fā)關(guān)閉浮層事件后攀唯,需要添加如下代碼恢復(fù)body滾動(dòng):
document.body.removeEventListener('touchmove',self.stopScroll);
//添加事件監(jiān)聽時(shí)添加了passive參數(shù)低飒,在ios9中移除事件監(jiān)聽也需要加此參數(shù)
document.body.removeEventListener('touchmove',self.stopScroll,{passive: true});
document.body.style.overflow = 'auto';