2

What is the easiest way to check if the window scroll is at the bottom—without using jQuery?

I've come across some methods, but most of them don't work cross browser.

David Sherret
  • 101,669
  • 28
  • 188
  • 178
Mia
  • 6,220
  • 12
  • 47
  • 81
  • 1
    possible duplicate of [Determining when scrolled to bottom of a page with Javascript](http://stackoverflow.com/questions/2817042/determining-when-scrolled-to-bottom-of-a-page-with-javascript) – Sam Hanley Nov 11 '14 at 03:36

1 Answers1

4

Here is one technique that works across a handful of browsers I tested

window.onscroll = function () {
    var totalHeight = document.documentElement.scrollHeight;
    var clientHeight = document.documentElement.clientHeight;
    var scrollTop = (document.body && document.body.scrollTop)
    ? document.body.scrollTop : document.documentElement.scrollTop;
    if (totalHeight == scrollTop + clientHeight)
        console.log('Bottom');
}
Jason W
  • 13,026
  • 3
  • 31
  • 62