直接说解决方案
// 弹框打开时 fixedBody = () => { const scrollTop = document.body.scrollTop || document.documentElement.scrollTop; document.body.style.setProperty('position', 'fixed'); document.body.style.setProperty('top', `${-scrollTop}px`); }; // 关闭时 resetBody = () => { document.body.style.setProperty('position', ''); document.documentElement.scrollTop = -parseInt(document.body.style.top); };