Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Last active November 27, 2023 04:51
Show Gist options
  • Save nathansmith/8939548 to your computer and use it in GitHub Desktop.
Save nathansmith/8939548 to your computer and use it in GitHub Desktop.
Check if the user is scrolled to the bottom of the page.
window.onscroll = function() {
var d = document.documentElement;
var offset = d.scrollTop + window.innerHeight;
var height = d.offsetHeight;
console.log('offset = ' + offset);
console.log('height = ' + height);
if (offset >= height) {
console.log('At the bottom');
}
};
@iooe
Copy link

iooe commented Nov 22, 2018

@whitehorse0 jquery, meh

@yamankatby
Copy link

Not working on Safari

@audinue
Copy link

audinue commented Mar 5, 2020

FYI scrollTop on chrome android 80 returns float

@muhammadyahyaa
Copy link

muhammadyahyaa commented Apr 1, 2020

Not working on Safari

The following code work for me in safari.

$(window).on("scroll", function() { if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) { }}

@alexalannunes
Copy link

alexalannunes commented Feb 9, 2021

Niceee 👏

But there's a problem with these solutions.
When the page is Zoomed.

The numbers of the height stays float

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment