Last active
September 10, 2019 21:42
-
-
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
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
## 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