推荐方法
给body fixed定位,即可屏蔽滚动,仍保留滚动条,页面不会变形
stopBodyScroll = (isFixed) => {
let bodyEl = document.body
let top = 0
if (isFixed) {
top = window.scrollY
bodyEl.style.position = 'fixed'
bodyEl.style.top = -top + 'px'
this.setState({top: top})
} else {
bodyEl.style.position = ''
bodyEl.style.top = ''
window.scrollTo(0, this.state.top) // 回到原先的top
}
}
记得,取消这一状态