异常场景:
h5活动页,手写弹窗,弹窗中有列表滚动,滚动到底,继续滚动,会发现弹窗背后页面发生滚动
(此场景的也买你高度也是足够高,产生了滚动条)
解决方案:
监听弹层打开状态,调整body为固定定位,禁止滚动,以此来解决此类问题
代码示例
1.弹窗打开时
const top = document.documentElement.scrollTop || document.body.scrollTop;
document.body.style.cssText += 'positionL fixed;width: 100vw;left: 0;top: ${-top}px;
2.弹窗关闭时
const top = document.body.style.top;
document.body.style.cssText += 'position: static;'
window.scrollTo(0, Math.abs(parseFloat(top)));