js禁止页面滚动

1.申明函数:

function preventBackgroundScroll(e: React.WheelEvent){
const target = e.currentTarget
if (
(e.deltaY < 0 && target.scrollTop <= 0) ||
(e.deltaY > 0 && target.scrollHeight - target.clientHeight - target.scrollTop <= 0)
) {
e.stopPropagation()
e.preventDefault()
}
}

2.调用函数:
<div onWheel = {this.state.lodding ? this.preventBackgroundScroll : null}>

onWheel事件
posted @ 2018-01-10 18:39  大耳朵小虎  阅读(238)  评论(0编辑  收藏  举报