打开弹窗后固定页面滚动或者允许页面滚动

1.固定页面

const openMaskFun = () => {
    
    
    let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
    document.body.style.cssText += 'position:fixed;width:100%;top:-' + scrollTop + 'px;';
};

2.允许页面滚动

const closeMaskFun = () => {
    
    
    let body = document.body;
    body.style.position = '';
    let top = body.style.top;
    document.body.scrollTop = document.documentElement.scrollTop = -parseInt(top);
    body.style.top = '';
};

猜你喜欢

转载自blog.csdn.net/weixin_49295874/article/details/129212909