Created
December 12, 2018 01:48
-
-
Save donhenton/c5627242d6adab398809f23fca55fc80 to your computer and use it in GitHub Desktop.
detect if a browser hits bottom
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
isAtScrollBottom() { | |
//https://gist.github.com/nathansmith/8939548 | |
//https://www.quora.com/How-do-you-detect-in-JavaScript-when-a-user-has-scrolled-to-the-bottom-of-the-page | |
//https://stackoverflow.com/questions/1145850/how-to-get-height-of-entire-document-with-javascript | |
//https://techstacker.com/posts/gGyGTHysrPuuJnNBk/vanilla-javascript-detect-when-user-scrolled-to-the-bottom | |
let body = document.body; | |
let html = document.documentElement; | |
var height = Math.max(body.scrollHeight, body.offsetHeight, | |
html.clientHeight, html.scrollHeight, html.offsetHeight); | |
if ((window.innerHeight + Math.ceil(window.pageYOffset)) >= height) { | |
console.log('At the bottom!'); | |
return true; | |
} | |
return false; | |
// console.log(`innerHeight ${window.innerHeight} scroll ${Math.ceil(window.pageYOffset)} height ${height}`) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment