Skip to content

Instantly share code, notes, and snippets.

@ezirmusitua
Last active September 10, 2019 21:42
Show Gist options
  • Save ezirmusitua/172b1f4ebd466825678356844b9b2bc6 to your computer and use it in GitHub Desktop.
Save ezirmusitua/172b1f4ebd466825678356844b9b2bc6 to your computer and use it in GitHub Desktop.
[Detect Scroll To Bottom] Detect Is User Scroll To Element Bottom #javascript #html
## Reference: https://stackoverflow.com/questions/45585542/detecting-when-user-scrolls-to-bottom-of-div-with-react-js
function isBottom(el) {
return el.getBoundingClientRect().bottom <= window.innerHeight;
}
function trackScrolling() {
const wrappedElement = document.querySelector(<target>);
if (isBottom(wrappedElement)) {
console.log('header bottom reached');
document.removeEventListener('scroll', this.trackScrolling);
}
}
function listen(el) {
el.addEventListener('scroll', trackScrolling);
}
function unlisten(el) {
el.removeEventListener('scroll', trackScrolling);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment