Created
September 7, 2019 15:56
-
-
Save shangdev/34bc396821e352af0367db608061d981 to your computer and use it in GitHub Desktop.
Detect scrolling event.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let overflowX = "auto"; | |
let overflowY = "auto"; | |
let scrollLeft = 0; | |
let scrollTop = 0; | |
let isScrolling; | |
const handleScroll = e => { | |
const element = e.target; | |
window.clearTimeout(isScrolling); | |
isScrolling = window.setTimeout(() => { | |
overflowX = "auto"; | |
overflowY = "auto"; | |
console.log("滚动停止"); | |
}, 250); | |
if (scrollLeft !== element.scrollLeft) { | |
scrollLeft = element.scrollLeft; | |
overflowY = "hidden"; | |
console.log(1); | |
console.log("水平滚动:" + scrollLeft); | |
} | |
if (scrollTop !== element.scrollTop) { | |
scrollTop = element.scrollTop; | |
overflowX = "hidden"; | |
console.log(2); | |
console.log("垂直滚动:" + scrollTop); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
demo: https://codesandbox.io/s/devextreme-react-grid-for-material-ui-rqvh4