Skip to content

Instantly share code, notes, and snippets.

@donhenton
Created December 12, 2018 01:48
Show Gist options
  • Save donhenton/c5627242d6adab398809f23fca55fc80 to your computer and use it in GitHub Desktop.
Save donhenton/c5627242d6adab398809f23fca55fc80 to your computer and use it in GitHub Desktop.
detect if a browser hits bottom
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