Scroll penetration
- Scroll to drive the inner layer
body.modal-open {
position: fixed;
}
var ModalHelper = (function (bodyCls) {
var scrollTop;
return {
afterOpen: function () {
console.log(10);
scrollTop = document.scrollingElement.scrollTop;
document.body.classList.add(bodyCls);
document.body.style.top = -scrollTop + 'px';
},
beforeClose: function () {
console.log(20);
document.body.classList.remove(bodyCls);
document.scrollingElement.scrollTop = scrollTop;
}
};
})('modal-open');
/***进入遮罩层,禁止滑动***/
function stopScroll() {
ModalHelper.afterOpen();
}
/***取消滑动限制***/
function allowScroll() {
ModalHelper.beforeClose()
}