Skip to content

Instantly share code, notes, and snippets.

@justforuse
Created May 25, 2021 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justforuse/db3478b8a833ce3f6858dbc9a84882ed to your computer and use it in GitHub Desktop.
Save justforuse/db3478b8a833ce3f6858dbc9a84882ed to your computer and use it in GitHub Desktop.
Detect whether element scroll to the end
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