react弹出一个对话框后禁止下层的滚动

在滚动内容上添加onWheel = { preventBackgroundScroll }

export const 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()
  }
}

你可能感兴趣的:(react弹出一个对话框后禁止下层的滚动)