Created
May 25, 2021 09:04
-
-
Save justforuse/db3478b8a833ce3f6858dbc9a84882ed to your computer and use it in GitHub Desktop.
Detect whether element scroll to the end
This file contains hidden or 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
function detectWhetherElementScrollToEnd(element) { | |
const { scrollLeft, scrollTop, offsetWidth, offsetHeight, scrollWidth, scrollHeight } = element; | |
if (scrollTop === 0) { | |
return 'scroll to top'; | |
} | |
if (scrollTop + offsetHeight >= scrollHeight) { | |
return 'scroll to end'; | |
} | |
if (scrollLeft === 0) { | |
return 'scroll to left'; | |
} | |
if (scrollLeft + offsetWidth >= scrollWidth) { | |
return 'scroll to right'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment