/**
* 添加fix定位解决滚动穿透
* @return {Number} 文档滚动高度
*/
scrollAddfix() {
let theTop = 0; // 文档滑动距离
let bodyEl = document.body
theTop = window.scrollY
bodyEl.style.position = 'fixed'
bodyEl.style.top = -theTop + 'px'
bodyEl.style.width = '100vw'; // 不设置这个可能会出现宽度被撑大问题
return theTop;
},
/**
* 重置body样式
* @param {Number} theTop 弹窗打开时文档滚动高度
*/
scrollReleasefix(theTop) {
let bodyEl = document.body
bodyEl.style.position = ''
bodyEl.style.top = ''
window.scrollTo(0, theTop) // 回到原先的top
}
h5解决滚动穿透
最新推荐文章于 2023-08-02 11:30:08 发布