// 弹出框 背景滑动问题 style.cssText 弹出框父级absolute body fixed 弹出框absolute 也是一种解决方案
val 变量,当前弹出框状态
huaDong (val) {
let scrollTop = 0
if (document.scrollingElement) {
scrollTop = document.scrollingElement.scrollTop
} else {
scrollTop = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset || 0
}
const bodyTag = window.document.getElementsByTagName('body')[0]
val ? bodyTag.classList.add('com-mask-background') : bodyTag.classList.remove('com-mask-background')
val ? bodyTag.style.top = -scrollTop + 'px' : window.scrollTo(0, -parseInt(bodyTag.style.top, 10))
},
css
.com-mask-background {
position: fixed;
height: 100%;
width: 100%;
overflow: hidden;
}