Check if a user has scrolled to the bottom












580















I'm making a pagination system (sort of like Facebook) where the content loads when the user scrolls to the bottom. I imagine the best way to do that is to find when the user is at the bottom of the page and run an ajax query to load more posts.



The only problem is I don't know how to check if the user has scrolled to the bottom of the page with jQuery. Any ideas?



I need to find a way to check when the user has scrolled to the bottom of the page with jQuery.










share|improve this question




















  • 1





    Possible duplicate of Javascript: How to detect if browser window is scrolled to bottom?

    – Flimm
    Feb 6 '18 at 7:11











  • That's funny, I'm trying to figure out which function is being called when I scroll to the bottom, so I can block this infuriating "feature".

    – endolith
    Jul 3 '18 at 16:08
















580















I'm making a pagination system (sort of like Facebook) where the content loads when the user scrolls to the bottom. I imagine the best way to do that is to find when the user is at the bottom of the page and run an ajax query to load more posts.



The only problem is I don't know how to check if the user has scrolled to the bottom of the page with jQuery. Any ideas?



I need to find a way to check when the user has scrolled to the bottom of the page with jQuery.










share|improve this question




















  • 1





    Possible duplicate of Javascript: How to detect if browser window is scrolled to bottom?

    – Flimm
    Feb 6 '18 at 7:11











  • That's funny, I'm trying to figure out which function is being called when I scroll to the bottom, so I can block this infuriating "feature".

    – endolith
    Jul 3 '18 at 16:08














580












580








580


230






I'm making a pagination system (sort of like Facebook) where the content loads when the user scrolls to the bottom. I imagine the best way to do that is to find when the user is at the bottom of the page and run an ajax query to load more posts.



The only problem is I don't know how to check if the user has scrolled to the bottom of the page with jQuery. Any ideas?



I need to find a way to check when the user has scrolled to the bottom of the page with jQuery.










share|improve this question
















I'm making a pagination system (sort of like Facebook) where the content loads when the user scrolls to the bottom. I imagine the best way to do that is to find when the user is at the bottom of the page and run an ajax query to load more posts.



The only problem is I don't know how to check if the user has scrolled to the bottom of the page with jQuery. Any ideas?



I need to find a way to check when the user has scrolled to the bottom of the page with jQuery.







javascript jquery scroll pagination






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 14 '16 at 12:21









Thomas Orlita

1,089921




1,089921










asked Oct 9 '10 at 22:28









JohnnyJohnny

3,54352029




3,54352029








  • 1





    Possible duplicate of Javascript: How to detect if browser window is scrolled to bottom?

    – Flimm
    Feb 6 '18 at 7:11











  • That's funny, I'm trying to figure out which function is being called when I scroll to the bottom, so I can block this infuriating "feature".

    – endolith
    Jul 3 '18 at 16:08














  • 1





    Possible duplicate of Javascript: How to detect if browser window is scrolled to bottom?

    – Flimm
    Feb 6 '18 at 7:11











  • That's funny, I'm trying to figure out which function is being called when I scroll to the bottom, so I can block this infuriating "feature".

    – endolith
    Jul 3 '18 at 16:08








1




1





Possible duplicate of Javascript: How to detect if browser window is scrolled to bottom?

– Flimm
Feb 6 '18 at 7:11





Possible duplicate of Javascript: How to detect if browser window is scrolled to bottom?

– Flimm
Feb 6 '18 at 7:11













That's funny, I'm trying to figure out which function is being called when I scroll to the bottom, so I can block this infuriating "feature".

– endolith
Jul 3 '18 at 16:08





That's funny, I'm trying to figure out which function is being called when I scroll to the bottom, so I can block this infuriating "feature".

– endolith
Jul 3 '18 at 16:08












21 Answers
21






active

oldest

votes


















916














Use the .scroll() event on window, like this:



$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});


You can test it here, this takes the top scroll of the window, so how much it's scrolled down, adds the height of the visible window and checks if that equals the height of the overall content (document). If you wanted to instead check if the user is near the bottom, it'd look something like this:



$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
alert("near bottom!");
}
});


You can test that version here, just adjust that 100 to whatever pixel from the bottom you want to trigger on.






share|improve this answer





















  • 30





    As usual you get there before me. Anyway, to the OP, if you have a container of posts, use it's ID instead of "window", also, you might want to change the last .height() to scrollHeight

    – Christian
    Oct 9 '10 at 22:40






  • 9





    it works great! but isnt it a bit heavy? on each scroll?

    – Kevin Vella
    Apr 18 '12 at 14:49






  • 3





    Firefox calls alert("bottom!"); many times (works fine with chrome and safari)

    – Marco Matarazzi
    Aug 13 '12 at 14:09






  • 15





    @KevinVella Vella good combination is to use this with _.debounce() in underscore utility to prevent it firing until user has stopped scrolling - underscorejs.org/#debounce -

    – JohnnyFaldo
    Feb 10 '14 at 11:27






  • 10





    I doesn't work if the user zoom in or zoom out the browser.

    – lvarayut
    May 28 '14 at 12:13





















105














Nick Craver's answer works fine, spare the issue that the value of $(document).height() varies by browser.



To make it work on all browsers, use this function from James Padolsey:



function getDocHeight() {
var D = document;
return Math.max(
D.body.scrollHeight, D.documentElement.scrollHeight,
D.body.offsetHeight, D.documentElement.offsetHeight,
D.body.clientHeight, D.documentElement.clientHeight
);
}


in place of $(document).height(), so that the final code is:



$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == getDocHeight()) {
alert("bottom!");
}
});





share|improve this answer





















  • 5





    He has updated with a slightly compressed version function getDocHeight() { var D = document; return Math.max( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); }

    – Drew
    Jul 26 '13 at 14:43











  • that alerts me when I reach the top, not the bottom (Chrome).

    – Damien Roche
    Jul 25 '18 at 9:07





















64














I'm not exactly sure why this has not been posted yet, but as per the documentation from MDN, the simplest way is by using native javascript properties:



element.scrollHeight - element.scrollTop === element.clientHeight


Returns true when you're at the bottom of any scrollable element. So simply using javascript:



element.addEventListener('scroll', function(event)
{
var element = event.target;
if (element.scrollHeight - element.scrollTop === element.clientHeight)
{
console.log('scrolled');
}
});


scrollHeight have wide support in browsers, from ie 8 to be more precise, while clientHeight and scrollTop are both supported by everyone. Even ie 6. This should be cross browser safe.






share|improve this answer



















  • 1





    Note that in some situations this may not be the case. Firefox 47 reports a textarea clientHeight as 239 while the above equation gives 253 when scrolled to the bottom. Maybe padding/border or something is affecting it? Either way, adding some wiggle room wouldn't hurt, like var isAtBottom = ( logField.scrollHeight - logField.scrollTop <= logField.clientHeight + 50 );. This is useful for auto-scrolling a field only if already at the bottom (so the user can manually examine a specific part of a realtime log without losing their place, etc).

    – Beejor
    Aug 19 '16 at 9:30











  • I would add that it's possible for it to return false negatives as one side could return a small decimal while the other side returns a whole number (eg. 200.181819304947 and 200). I added a Math.floor() to help deal with that but I don't know how reliable this will be.

    – Hanna
    Nov 7 '16 at 22:44











  • For me, this doesn't work cross browser. I get completely different results on chrome compared to firefox.

    – JedatKinports
    Dec 20 '16 at 13:45






  • 1





    I tried this on the <body> element, and this is firing when the browser is scrolled to the TOP, not the bottom.

    – Chris Sobolewski
    Jan 31 '17 at 16:07






  • 1





    Math.abs(element.scrollHeight - element.scrollTop - element.clientHeight) <= 3.0 (replace 3.0 with whatever pixel tolerance you think is appropriate for your circumstances). This is the way to go because (A) clientHeight, scrollTop, and clientHeight are all rounded which could potentially lead to a 3px error if all align, (B) 3 pixels is hardly visible to the user so the user may think something is wrong with your site when they "think" they are at the bottom of the page when in fact they are not, and (C) certain devices (especially mouseless ones) can have odd behavior when scrolling.

    – Jack Giffin
    Oct 21 '18 at 18:50





















44














For those using Nick's solution and getting repeated alerts / events firing, you could add a line of code above the alert example:



$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
$(window).unbind('scroll');
alert("near bottom!");
}
});


This means that the code will only fire the first time you're within 100px of the bottom of the document. It won't repeat if you scroll back up and then back down, which may or may not be useful depending on what you're using Nick's code for.






share|improve this answer



















  • 1





    I would've just commented and said where that line of code is since its relevant to someone else's answer but +1 for the intention!

    – Nate-Wilkins
    Oct 1 '12 at 17:07











  • Sorry, I couldn't (and still can't) see how to add a comment to the answer (like I can here)?

    – Tim Carr
    Oct 1 '12 at 19:12











  • Yea new users can't add a comment to posts unless you get more rep.

    – Nate-Wilkins
    Oct 1 '12 at 21:12











  • Out side the first if you could put a different if that tests if the change you wanted the script to make exists, say a class having been applied to a div. This would make the second nested if not run if it has already run.

    – fredsbend
    Jan 31 '13 at 9:06













  • how can i select particular div id instead of the whole window?

    – James Smith
    Mar 23 '15 at 3:28



















39














Further to the excellent accepted answer from Nick Craver, you can throttle the scroll event so that it is not fired so frequently thus increasing browser performance:



var _throttleTimer = null;
var _throttleDelay = 100;
var $window = $(window);
var $document = $(document);

$document.ready(function () {

$window
.off('scroll', ScrollHandler)
.on('scroll', ScrollHandler);

});

function ScrollHandler(e) {
//throttle event:
clearTimeout(_throttleTimer);
_throttleTimer = setTimeout(function () {
console.log('scroll');

//do work
if ($window.scrollTop() + $window.height() > $document.height() - 100) {
alert("near bottom!");
}

}, _throttleDelay);
}





share|improve this answer


























  • It should probably be pointed out that this requires Underscore.js: underscorejs.org. It's a very good point, though. The scroll event should pretty much always be throttled to avoid serious performance issues.

    – Jude Osborn
    Jun 18 '13 at 8:21








  • 34





    The above code does NOT require Underscore.js

    – George Filippakos
    Jun 19 '13 at 9:03











  • Maybe it's just me and it could use some benchmarking, but I don't like the idea of invoking clearTimeout and setTimeout on every scroll event. I would issue 1 setTimeout and add some guards in that handler. It's probably just a micro-optimization (if at all).

    – Grimace of Despair
    Sep 16 '13 at 14:31











  • This is a really neat addition! I can think of one further improvement . Currently the function that checks the height wont run if the user continues to scroll. If this is a problem (e.g. you want to trigger the function when the user scrolled half way down regardless of if they keep scrolling) you can easily make sure that the function actually gets called while still prohibiting multiple calls during the chosen interval. Here is a gist to show it. gist.github.com/datacarl/7029558

    – datacarl
    Oct 17 '13 at 18:16











  • What? Invoke a load of machinery to prevent a simple calculation? I don't see how that is more efficient at all

    – Rambatino
    Nov 26 '17 at 10:14



















35














Nick Craver's answer needs to be slightly modified to work on iOS 6 Safari Mobile and should be:



$(window).scroll(function() {
if($(window).scrollTop() + window.innerHeight == $(document).height()) {
alert("bottom!");
}
});


Changing $(window).height() to window.innerHeight should be done because when the address bar is hidden an additional 60px are added to the window's height but using $(window).height() does not reflect this change, while using window.innerHeight does.



Note: The window.innerHeight property also includes the horizontal scrollbar's height (if it is rendered), unlike $(window).height() which will not include the horizontal scrollbar's height. This is not a problem in Mobile Safari, but could cause unexpected behavior in other browsers or future versions of Mobile Safari. Changing == to >= could fix this for most common use cases.



Read more about the window.innerHeight property here






share|improve this answer


























  • window.innerHeight made more sense for what i was trying to accomplish thanks!

    – Amir5000
    Sep 18 '14 at 17:36











  • How to get remaining height after scroll?

    – OPV
    Aug 25 '18 at 0:46



















18














Here's a fairly simple approach:



elm.onscroll = function() {
if(elm.scrollTop + elm.clientHeight == elm.scrollHeight) //User has scrolled to the bottom of the element
}





share|improve this answer

































    14














    Here is a piece of code that will help you debug your code, I tested the above answers and found them to be buggy. I have test the followings on Chrome, IE, Firefox, IPad(Safari). I don't have any others installed to test...



    <script type="text/javascript">
    $(function() {
    $(window).scroll(function () {
    var docElement = $(document)[0].documentElement;
    var winElement = $(window)[0];

    if ((docElement.scrollHeight - winElement.innerHeight) == winElement.pageYOffset) {
    alert('bottom');
    }
    });
    });
    </script>


    There may be a simpler solution, but I stopped at the point at which IT WORKED



    If you are still having problems with some rogue browser, here is some code to help you debug:



    <script type="text/javascript">
    $(function() {
    $(window).scroll(function () {
    var docElement = $(document)[0].documentElement;
    var details = "";
    details += '<b>Document</b><br />';
    details += 'clientHeight:' + docElement.clientHeight + '<br />';
    details += 'clientTop:' + docElement.clientTop + '<br />';
    details += 'offsetHeight:' + docElement.offsetHeight + '<br />';
    details += 'offsetParent:' + (docElement.offsetParent == null) + '<br />';
    details += 'scrollHeight:' + docElement.scrollHeight + '<br />';
    details += 'scrollTop:' + docElement.scrollTop + '<br />';

    var winElement = $(window)[0];
    details += '<b>Window</b><br />';
    details += 'innerHeight:' + winElement.innerHeight + '<br />';
    details += 'outerHeight:' + winElement.outerHeight + '<br />';
    details += 'pageYOffset:' + winElement.pageYOffset + '<br />';
    details += 'screenTop:' + winElement.screenTop + '<br />';
    details += 'screenY:' + winElement.screenY + '<br />';
    details += 'scrollY:' + winElement.scrollY + '<br />';

    details += '<b>End of page</b><br />';
    details += 'Test:' + (docElement.scrollHeight - winElement.innerHeight) + '=' + winElement.pageYOffset + '<br />';
    details += 'End of Page? ';
    if ((docElement.scrollHeight - winElement.innerHeight) == winElement.pageYOffset) {
    details += 'YES';
    } else {
    details += 'NO';
    }

    $('#test').html(details);
    });
    });
    </script>
    <div id="test" style="position: fixed; left:0; top: 0; z-index: 9999; background-color: #FFFFFF;">


    I hope this will save someone some time.






    share|improve this answer


























    • Best answer for Vanilla js, No jQuery solution. Use var docElement = document.documentElement; var winElement = window

      – jperelli
      Jun 22 '16 at 15:04



















    10














    Please check this answer



     window.onscroll = function(ev) {
    if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
    console.log("bottom");
    }
    };


    You can do footerHeight - document.body.offsetHeight to see if you are near the footer or reached the footer






    share|improve this answer

































      10














      var elemScrolPosition = elem.scrollHeight - elem.scrollTop - elem.clientHeight;


      It calculates distance scroll bar to bottom of element.
      Equal 0, if scroll bar has reached bottom.






      share|improve this answer



















      • 1





        I did the following and worked flawlessly. Thanks. var shouldScroll = (elem.scrollHeight - elem.scrollTop - elem.clientHeight) == 0;

        – jiminssy
        Nov 20 '16 at 16:48





















      9














      This is my two cents:



      $('#container_element').scroll( function(){
      console.log($(this).scrollTop()+' + '+ $(this).height()+' = '+ ($(this).scrollTop() + $(this).height()) +' _ '+ $(this)[0].scrollHeight );
      if($(this).scrollTop() + $(this).height() == $(this)[0].scrollHeight){
      console.log('bottom found');
      }
      });





      share|improve this answer































        5














        Pure JS with cross-browser and debouncing (Pretty good performance)



        var CheckIfScrollBottom = debouncer(function() {
        if(getDocHeight() == getScrollXY()[1] + window.innerHeight) {
        console.log('Bottom!');
        }
        },500);

        document.addEventListener('scroll',CheckIfScrollBottom);

        function debouncer(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}
        function getScrollXY(){var a=0,b=0;return"number"==typeof window.pageYOffset?(b=window.pageYOffset,a=window.pageXOffset):document.body&&(document.body.scrollLeft||document.body.scrollTop)?(b=document.body.scrollTop,a=document.body.scrollLeft):document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)&&(b=document.documentElement.scrollTop,a=document.documentElement.scrollLeft),[a,b]}
        function getDocHeight(){var a=document;return Math.max(a.body.scrollHeight,a.documentElement.scrollHeight,a.body.offsetHeight,a.documentElement.offsetHeight,a.body.clientHeight,a.documentElement.clientHeight)}


        Demo : http://jsbin.com/geherovena/edit?js,output



        PS: Debouncer, getScrollXY, getDocHeight not written by me



        I just show how its work, And how I will do






        share|improve this answer


























        • Perfect. Tested in Firefox and Chrome

          – Erlisar Vasquez
          Nov 23 '18 at 3:14





















        2














        Nick answers its fine but you will have functions which repeats itsself while scrolling or will not work at all if user has the window zoomed. I came up with an easy fix just math.round the first height and it works just as assumed.



            if (Math.round($(window).scrollTop()) + $(window).innerHeight() == $(document).height()){
        loadPagination();
        $(".go-up").css("display","block").show("slow");
        }





        share|improve this answer































          2














          You can try the following code,



          $("#dashboard-scroll").scroll(function(){
          var ele = document.getElementById('dashboard-scroll');
          if(ele.scrollHeight - ele.scrollTop === ele.clientHeight){
          console.log('at the bottom of the scroll');
          }
          });





          share|improve this answer































            2














            Try this for match condition if scroll to bottom end



            if ($(this)[0].scrollHeight - $(this).scrollTop() == 
            $(this).outerHeight()) {

            //code for your custom logic

            }





            share|improve this answer

































              1














              Let me show approch without JQuery. Simple JS function:



              function isVisible(elem) {
              var coords = elem.getBoundingClientRect();
              var topVisible = coords.top > 0 && coords.top < 0;
              var bottomVisible = coords.bottom < shift && coords.bottom > 0;
              return topVisible || bottomVisible;
              }


              Short example how to use it:



              var img = document.getElementById("pic1");
              if (isVisible(img)) { img.style.opacity = "1.00"; }





              share|improve this answer





















              • 3





                This doesn't answer the question. The question was how to detect that the users has scrolled the window all the way to the bottom. Your code is checking if a particular element is in view.

                – Peter Hall
                Jan 5 '16 at 18:58



















              1














              All these solutions doesn't work for me on Firefox and Chrome, so I use custom functions from Miles O'Keefe and meder omuraliev like this:



              function getDocHeight()
              {
              var D = document;
              return Math.max(
              D.body.scrollHeight, D.documentElement.scrollHeight,
              D.body.offsetHeight, D.documentElement.offsetHeight,
              D.body.clientHeight, D.documentElement.clientHeight
              );
              }

              function getWindowSize()
              {
              var myWidth = 0, myHeight = 0;
              if( typeof( window.innerWidth ) == 'number' ) {
              //Non-IE
              myWidth = window.innerWidth;
              myHeight = window.innerHeight;
              } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
              //IE 6+ in 'standards compliant mode'
              myWidth = document.documentElement.clientWidth;
              myHeight = document.documentElement.clientHeight;
              } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
              //IE 4 compatible
              myWidth = document.body.clientWidth;
              myHeight = document.body.clientHeight;
              }
              return [myWidth, myHeight];
              }

              $(window).scroll(function()
              {
              if($(window).scrollTop() + getWindowSize()[1] == getDocHeight())
              {
              alert("bottom!");
              }
              });





              share|improve this answer































                0














                I used @ddanone answear and added Ajax call.



                $('#mydiv').on('scroll', function(){
                function infiniScroll(this);
                });

                function infiniScroll(mydiv){
                console.log($(mydiv).scrollTop()+' + '+ $(mydiv).height()+' = '+ ($(mydiv).scrollTop() + $(mydiv).height()) +' _ '+ $(mydiv)[0].scrollHeight );

                if($(mydiv).scrollTop() + $(mydiv).height() == $(mydiv)[0].scrollHeight){
                console.log('bottom found');
                if(!$.active){ //if there is no ajax call active ( last ajax call waiting for results ) do again my ajax call
                myAjaxCall();
                }
                }


                }






                share|improve this answer































                  0














                  To stop repeated alert of Nick's answer



                  ScrollActivate();

                  function ScrollActivate() {
                  $(window).on("scroll", function () {
                  if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                  $(window).off("scroll");
                  alert("near bottom!");
                  }
                  });
                  }





                  share|improve this answer































                    0














                    My solution in plain js:






                    let el=document.getElementById('el');
                    el.addEventListener('scroll', function (e) {
                    if (el.scrollHeight - el.scrollTop - el.clientHeight<0) {
                    console.log('Bottom')
                    }
                    });

                    #el{
                    width:300px;
                    height:100px;
                    overflow-y:scroll;
                    }

                    <div id="el">
                    <div>content</div>
                    <div>content</div>
                    <div>content</div>
                    <div>content</div>
                    <div>content</div>
                    <div>content</div>
                    <div>content</div>
                    <div>content</div>
                    <div>content</div>
                    <div>content</div>
                    <div>content</div>
                    </div>








                    share|improve this answer































                      0














                      Here's my two cents as the accepted answer didn't work for me.



                      var documentAtBottom = (document.documentElement.scrollTop + window.innerHeight) >= document.documentElement.scrollHeight;





                      share|improve this answer
























                        protected by animuson Sep 24 '13 at 20:41



                        Thank you for your interest in this question.
                        Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                        Would you like to answer one of these unanswered questions instead?














                        21 Answers
                        21






                        active

                        oldest

                        votes








                        21 Answers
                        21






                        active

                        oldest

                        votes









                        active

                        oldest

                        votes






                        active

                        oldest

                        votes









                        916














                        Use the .scroll() event on window, like this:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() == $(document).height()) {
                        alert("bottom!");
                        }
                        });


                        You can test it here, this takes the top scroll of the window, so how much it's scrolled down, adds the height of the visible window and checks if that equals the height of the overall content (document). If you wanted to instead check if the user is near the bottom, it'd look something like this:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                        alert("near bottom!");
                        }
                        });


                        You can test that version here, just adjust that 100 to whatever pixel from the bottom you want to trigger on.






                        share|improve this answer





















                        • 30





                          As usual you get there before me. Anyway, to the OP, if you have a container of posts, use it's ID instead of "window", also, you might want to change the last .height() to scrollHeight

                          – Christian
                          Oct 9 '10 at 22:40






                        • 9





                          it works great! but isnt it a bit heavy? on each scroll?

                          – Kevin Vella
                          Apr 18 '12 at 14:49






                        • 3





                          Firefox calls alert("bottom!"); many times (works fine with chrome and safari)

                          – Marco Matarazzi
                          Aug 13 '12 at 14:09






                        • 15





                          @KevinVella Vella good combination is to use this with _.debounce() in underscore utility to prevent it firing until user has stopped scrolling - underscorejs.org/#debounce -

                          – JohnnyFaldo
                          Feb 10 '14 at 11:27






                        • 10





                          I doesn't work if the user zoom in or zoom out the browser.

                          – lvarayut
                          May 28 '14 at 12:13


















                        916














                        Use the .scroll() event on window, like this:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() == $(document).height()) {
                        alert("bottom!");
                        }
                        });


                        You can test it here, this takes the top scroll of the window, so how much it's scrolled down, adds the height of the visible window and checks if that equals the height of the overall content (document). If you wanted to instead check if the user is near the bottom, it'd look something like this:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                        alert("near bottom!");
                        }
                        });


                        You can test that version here, just adjust that 100 to whatever pixel from the bottom you want to trigger on.






                        share|improve this answer





















                        • 30





                          As usual you get there before me. Anyway, to the OP, if you have a container of posts, use it's ID instead of "window", also, you might want to change the last .height() to scrollHeight

                          – Christian
                          Oct 9 '10 at 22:40






                        • 9





                          it works great! but isnt it a bit heavy? on each scroll?

                          – Kevin Vella
                          Apr 18 '12 at 14:49






                        • 3





                          Firefox calls alert("bottom!"); many times (works fine with chrome and safari)

                          – Marco Matarazzi
                          Aug 13 '12 at 14:09






                        • 15





                          @KevinVella Vella good combination is to use this with _.debounce() in underscore utility to prevent it firing until user has stopped scrolling - underscorejs.org/#debounce -

                          – JohnnyFaldo
                          Feb 10 '14 at 11:27






                        • 10





                          I doesn't work if the user zoom in or zoom out the browser.

                          – lvarayut
                          May 28 '14 at 12:13
















                        916












                        916








                        916







                        Use the .scroll() event on window, like this:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() == $(document).height()) {
                        alert("bottom!");
                        }
                        });


                        You can test it here, this takes the top scroll of the window, so how much it's scrolled down, adds the height of the visible window and checks if that equals the height of the overall content (document). If you wanted to instead check if the user is near the bottom, it'd look something like this:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                        alert("near bottom!");
                        }
                        });


                        You can test that version here, just adjust that 100 to whatever pixel from the bottom you want to trigger on.






                        share|improve this answer















                        Use the .scroll() event on window, like this:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() == $(document).height()) {
                        alert("bottom!");
                        }
                        });


                        You can test it here, this takes the top scroll of the window, so how much it's scrolled down, adds the height of the visible window and checks if that equals the height of the overall content (document). If you wanted to instead check if the user is near the bottom, it'd look something like this:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                        alert("near bottom!");
                        }
                        });


                        You can test that version here, just adjust that 100 to whatever pixel from the bottom you want to trigger on.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Oct 9 '10 at 22:39

























                        answered Oct 9 '10 at 22:34









                        Nick CraverNick Craver

                        531k11511951102




                        531k11511951102








                        • 30





                          As usual you get there before me. Anyway, to the OP, if you have a container of posts, use it's ID instead of "window", also, you might want to change the last .height() to scrollHeight

                          – Christian
                          Oct 9 '10 at 22:40






                        • 9





                          it works great! but isnt it a bit heavy? on each scroll?

                          – Kevin Vella
                          Apr 18 '12 at 14:49






                        • 3





                          Firefox calls alert("bottom!"); many times (works fine with chrome and safari)

                          – Marco Matarazzi
                          Aug 13 '12 at 14:09






                        • 15





                          @KevinVella Vella good combination is to use this with _.debounce() in underscore utility to prevent it firing until user has stopped scrolling - underscorejs.org/#debounce -

                          – JohnnyFaldo
                          Feb 10 '14 at 11:27






                        • 10





                          I doesn't work if the user zoom in or zoom out the browser.

                          – lvarayut
                          May 28 '14 at 12:13
















                        • 30





                          As usual you get there before me. Anyway, to the OP, if you have a container of posts, use it's ID instead of "window", also, you might want to change the last .height() to scrollHeight

                          – Christian
                          Oct 9 '10 at 22:40






                        • 9





                          it works great! but isnt it a bit heavy? on each scroll?

                          – Kevin Vella
                          Apr 18 '12 at 14:49






                        • 3





                          Firefox calls alert("bottom!"); many times (works fine with chrome and safari)

                          – Marco Matarazzi
                          Aug 13 '12 at 14:09






                        • 15





                          @KevinVella Vella good combination is to use this with _.debounce() in underscore utility to prevent it firing until user has stopped scrolling - underscorejs.org/#debounce -

                          – JohnnyFaldo
                          Feb 10 '14 at 11:27






                        • 10





                          I doesn't work if the user zoom in or zoom out the browser.

                          – lvarayut
                          May 28 '14 at 12:13










                        30




                        30





                        As usual you get there before me. Anyway, to the OP, if you have a container of posts, use it's ID instead of "window", also, you might want to change the last .height() to scrollHeight

                        – Christian
                        Oct 9 '10 at 22:40





                        As usual you get there before me. Anyway, to the OP, if you have a container of posts, use it's ID instead of "window", also, you might want to change the last .height() to scrollHeight

                        – Christian
                        Oct 9 '10 at 22:40




                        9




                        9





                        it works great! but isnt it a bit heavy? on each scroll?

                        – Kevin Vella
                        Apr 18 '12 at 14:49





                        it works great! but isnt it a bit heavy? on each scroll?

                        – Kevin Vella
                        Apr 18 '12 at 14:49




                        3




                        3





                        Firefox calls alert("bottom!"); many times (works fine with chrome and safari)

                        – Marco Matarazzi
                        Aug 13 '12 at 14:09





                        Firefox calls alert("bottom!"); many times (works fine with chrome and safari)

                        – Marco Matarazzi
                        Aug 13 '12 at 14:09




                        15




                        15





                        @KevinVella Vella good combination is to use this with _.debounce() in underscore utility to prevent it firing until user has stopped scrolling - underscorejs.org/#debounce -

                        – JohnnyFaldo
                        Feb 10 '14 at 11:27





                        @KevinVella Vella good combination is to use this with _.debounce() in underscore utility to prevent it firing until user has stopped scrolling - underscorejs.org/#debounce -

                        – JohnnyFaldo
                        Feb 10 '14 at 11:27




                        10




                        10





                        I doesn't work if the user zoom in or zoom out the browser.

                        – lvarayut
                        May 28 '14 at 12:13







                        I doesn't work if the user zoom in or zoom out the browser.

                        – lvarayut
                        May 28 '14 at 12:13















                        105














                        Nick Craver's answer works fine, spare the issue that the value of $(document).height() varies by browser.



                        To make it work on all browsers, use this function from James Padolsey:



                        function getDocHeight() {
                        var D = document;
                        return Math.max(
                        D.body.scrollHeight, D.documentElement.scrollHeight,
                        D.body.offsetHeight, D.documentElement.offsetHeight,
                        D.body.clientHeight, D.documentElement.clientHeight
                        );
                        }


                        in place of $(document).height(), so that the final code is:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() == getDocHeight()) {
                        alert("bottom!");
                        }
                        });





                        share|improve this answer





















                        • 5





                          He has updated with a slightly compressed version function getDocHeight() { var D = document; return Math.max( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); }

                          – Drew
                          Jul 26 '13 at 14:43











                        • that alerts me when I reach the top, not the bottom (Chrome).

                          – Damien Roche
                          Jul 25 '18 at 9:07


















                        105














                        Nick Craver's answer works fine, spare the issue that the value of $(document).height() varies by browser.



                        To make it work on all browsers, use this function from James Padolsey:



                        function getDocHeight() {
                        var D = document;
                        return Math.max(
                        D.body.scrollHeight, D.documentElement.scrollHeight,
                        D.body.offsetHeight, D.documentElement.offsetHeight,
                        D.body.clientHeight, D.documentElement.clientHeight
                        );
                        }


                        in place of $(document).height(), so that the final code is:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() == getDocHeight()) {
                        alert("bottom!");
                        }
                        });





                        share|improve this answer





















                        • 5





                          He has updated with a slightly compressed version function getDocHeight() { var D = document; return Math.max( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); }

                          – Drew
                          Jul 26 '13 at 14:43











                        • that alerts me when I reach the top, not the bottom (Chrome).

                          – Damien Roche
                          Jul 25 '18 at 9:07
















                        105












                        105








                        105







                        Nick Craver's answer works fine, spare the issue that the value of $(document).height() varies by browser.



                        To make it work on all browsers, use this function from James Padolsey:



                        function getDocHeight() {
                        var D = document;
                        return Math.max(
                        D.body.scrollHeight, D.documentElement.scrollHeight,
                        D.body.offsetHeight, D.documentElement.offsetHeight,
                        D.body.clientHeight, D.documentElement.clientHeight
                        );
                        }


                        in place of $(document).height(), so that the final code is:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() == getDocHeight()) {
                        alert("bottom!");
                        }
                        });





                        share|improve this answer















                        Nick Craver's answer works fine, spare the issue that the value of $(document).height() varies by browser.



                        To make it work on all browsers, use this function from James Padolsey:



                        function getDocHeight() {
                        var D = document;
                        return Math.max(
                        D.body.scrollHeight, D.documentElement.scrollHeight,
                        D.body.offsetHeight, D.documentElement.offsetHeight,
                        D.body.clientHeight, D.documentElement.clientHeight
                        );
                        }


                        in place of $(document).height(), so that the final code is:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() == getDocHeight()) {
                        alert("bottom!");
                        }
                        });






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited May 8 '14 at 22:39









                        iwasrobbed

                        41.3k16119175




                        41.3k16119175










                        answered May 29 '12 at 8:42









                        Miles O'KeefeMiles O'Keefe

                        1,22811017




                        1,22811017








                        • 5





                          He has updated with a slightly compressed version function getDocHeight() { var D = document; return Math.max( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); }

                          – Drew
                          Jul 26 '13 at 14:43











                        • that alerts me when I reach the top, not the bottom (Chrome).

                          – Damien Roche
                          Jul 25 '18 at 9:07
















                        • 5





                          He has updated with a slightly compressed version function getDocHeight() { var D = document; return Math.max( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); }

                          – Drew
                          Jul 26 '13 at 14:43











                        • that alerts me when I reach the top, not the bottom (Chrome).

                          – Damien Roche
                          Jul 25 '18 at 9:07










                        5




                        5





                        He has updated with a slightly compressed version function getDocHeight() { var D = document; return Math.max( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); }

                        – Drew
                        Jul 26 '13 at 14:43





                        He has updated with a slightly compressed version function getDocHeight() { var D = document; return Math.max( D.body.scrollHeight, D.documentElement.scrollHeight, D.body.offsetHeight, D.documentElement.offsetHeight, D.body.clientHeight, D.documentElement.clientHeight ); }

                        – Drew
                        Jul 26 '13 at 14:43













                        that alerts me when I reach the top, not the bottom (Chrome).

                        – Damien Roche
                        Jul 25 '18 at 9:07







                        that alerts me when I reach the top, not the bottom (Chrome).

                        – Damien Roche
                        Jul 25 '18 at 9:07













                        64














                        I'm not exactly sure why this has not been posted yet, but as per the documentation from MDN, the simplest way is by using native javascript properties:



                        element.scrollHeight - element.scrollTop === element.clientHeight


                        Returns true when you're at the bottom of any scrollable element. So simply using javascript:



                        element.addEventListener('scroll', function(event)
                        {
                        var element = event.target;
                        if (element.scrollHeight - element.scrollTop === element.clientHeight)
                        {
                        console.log('scrolled');
                        }
                        });


                        scrollHeight have wide support in browsers, from ie 8 to be more precise, while clientHeight and scrollTop are both supported by everyone. Even ie 6. This should be cross browser safe.






                        share|improve this answer



















                        • 1





                          Note that in some situations this may not be the case. Firefox 47 reports a textarea clientHeight as 239 while the above equation gives 253 when scrolled to the bottom. Maybe padding/border or something is affecting it? Either way, adding some wiggle room wouldn't hurt, like var isAtBottom = ( logField.scrollHeight - logField.scrollTop <= logField.clientHeight + 50 );. This is useful for auto-scrolling a field only if already at the bottom (so the user can manually examine a specific part of a realtime log without losing their place, etc).

                          – Beejor
                          Aug 19 '16 at 9:30











                        • I would add that it's possible for it to return false negatives as one side could return a small decimal while the other side returns a whole number (eg. 200.181819304947 and 200). I added a Math.floor() to help deal with that but I don't know how reliable this will be.

                          – Hanna
                          Nov 7 '16 at 22:44











                        • For me, this doesn't work cross browser. I get completely different results on chrome compared to firefox.

                          – JedatKinports
                          Dec 20 '16 at 13:45






                        • 1





                          I tried this on the <body> element, and this is firing when the browser is scrolled to the TOP, not the bottom.

                          – Chris Sobolewski
                          Jan 31 '17 at 16:07






                        • 1





                          Math.abs(element.scrollHeight - element.scrollTop - element.clientHeight) <= 3.0 (replace 3.0 with whatever pixel tolerance you think is appropriate for your circumstances). This is the way to go because (A) clientHeight, scrollTop, and clientHeight are all rounded which could potentially lead to a 3px error if all align, (B) 3 pixels is hardly visible to the user so the user may think something is wrong with your site when they "think" they are at the bottom of the page when in fact they are not, and (C) certain devices (especially mouseless ones) can have odd behavior when scrolling.

                          – Jack Giffin
                          Oct 21 '18 at 18:50


















                        64














                        I'm not exactly sure why this has not been posted yet, but as per the documentation from MDN, the simplest way is by using native javascript properties:



                        element.scrollHeight - element.scrollTop === element.clientHeight


                        Returns true when you're at the bottom of any scrollable element. So simply using javascript:



                        element.addEventListener('scroll', function(event)
                        {
                        var element = event.target;
                        if (element.scrollHeight - element.scrollTop === element.clientHeight)
                        {
                        console.log('scrolled');
                        }
                        });


                        scrollHeight have wide support in browsers, from ie 8 to be more precise, while clientHeight and scrollTop are both supported by everyone. Even ie 6. This should be cross browser safe.






                        share|improve this answer



















                        • 1





                          Note that in some situations this may not be the case. Firefox 47 reports a textarea clientHeight as 239 while the above equation gives 253 when scrolled to the bottom. Maybe padding/border or something is affecting it? Either way, adding some wiggle room wouldn't hurt, like var isAtBottom = ( logField.scrollHeight - logField.scrollTop <= logField.clientHeight + 50 );. This is useful for auto-scrolling a field only if already at the bottom (so the user can manually examine a specific part of a realtime log without losing their place, etc).

                          – Beejor
                          Aug 19 '16 at 9:30











                        • I would add that it's possible for it to return false negatives as one side could return a small decimal while the other side returns a whole number (eg. 200.181819304947 and 200). I added a Math.floor() to help deal with that but I don't know how reliable this will be.

                          – Hanna
                          Nov 7 '16 at 22:44











                        • For me, this doesn't work cross browser. I get completely different results on chrome compared to firefox.

                          – JedatKinports
                          Dec 20 '16 at 13:45






                        • 1





                          I tried this on the <body> element, and this is firing when the browser is scrolled to the TOP, not the bottom.

                          – Chris Sobolewski
                          Jan 31 '17 at 16:07






                        • 1





                          Math.abs(element.scrollHeight - element.scrollTop - element.clientHeight) <= 3.0 (replace 3.0 with whatever pixel tolerance you think is appropriate for your circumstances). This is the way to go because (A) clientHeight, scrollTop, and clientHeight are all rounded which could potentially lead to a 3px error if all align, (B) 3 pixels is hardly visible to the user so the user may think something is wrong with your site when they "think" they are at the bottom of the page when in fact they are not, and (C) certain devices (especially mouseless ones) can have odd behavior when scrolling.

                          – Jack Giffin
                          Oct 21 '18 at 18:50
















                        64












                        64








                        64







                        I'm not exactly sure why this has not been posted yet, but as per the documentation from MDN, the simplest way is by using native javascript properties:



                        element.scrollHeight - element.scrollTop === element.clientHeight


                        Returns true when you're at the bottom of any scrollable element. So simply using javascript:



                        element.addEventListener('scroll', function(event)
                        {
                        var element = event.target;
                        if (element.scrollHeight - element.scrollTop === element.clientHeight)
                        {
                        console.log('scrolled');
                        }
                        });


                        scrollHeight have wide support in browsers, from ie 8 to be more precise, while clientHeight and scrollTop are both supported by everyone. Even ie 6. This should be cross browser safe.






                        share|improve this answer













                        I'm not exactly sure why this has not been posted yet, but as per the documentation from MDN, the simplest way is by using native javascript properties:



                        element.scrollHeight - element.scrollTop === element.clientHeight


                        Returns true when you're at the bottom of any scrollable element. So simply using javascript:



                        element.addEventListener('scroll', function(event)
                        {
                        var element = event.target;
                        if (element.scrollHeight - element.scrollTop === element.clientHeight)
                        {
                        console.log('scrolled');
                        }
                        });


                        scrollHeight have wide support in browsers, from ie 8 to be more precise, while clientHeight and scrollTop are both supported by everyone. Even ie 6. This should be cross browser safe.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Dec 31 '15 at 18:13









                        Félix Gagnon-GrenierFélix Gagnon-Grenier

                        5,55883946




                        5,55883946








                        • 1





                          Note that in some situations this may not be the case. Firefox 47 reports a textarea clientHeight as 239 while the above equation gives 253 when scrolled to the bottom. Maybe padding/border or something is affecting it? Either way, adding some wiggle room wouldn't hurt, like var isAtBottom = ( logField.scrollHeight - logField.scrollTop <= logField.clientHeight + 50 );. This is useful for auto-scrolling a field only if already at the bottom (so the user can manually examine a specific part of a realtime log without losing their place, etc).

                          – Beejor
                          Aug 19 '16 at 9:30











                        • I would add that it's possible for it to return false negatives as one side could return a small decimal while the other side returns a whole number (eg. 200.181819304947 and 200). I added a Math.floor() to help deal with that but I don't know how reliable this will be.

                          – Hanna
                          Nov 7 '16 at 22:44











                        • For me, this doesn't work cross browser. I get completely different results on chrome compared to firefox.

                          – JedatKinports
                          Dec 20 '16 at 13:45






                        • 1





                          I tried this on the <body> element, and this is firing when the browser is scrolled to the TOP, not the bottom.

                          – Chris Sobolewski
                          Jan 31 '17 at 16:07






                        • 1





                          Math.abs(element.scrollHeight - element.scrollTop - element.clientHeight) <= 3.0 (replace 3.0 with whatever pixel tolerance you think is appropriate for your circumstances). This is the way to go because (A) clientHeight, scrollTop, and clientHeight are all rounded which could potentially lead to a 3px error if all align, (B) 3 pixels is hardly visible to the user so the user may think something is wrong with your site when they "think" they are at the bottom of the page when in fact they are not, and (C) certain devices (especially mouseless ones) can have odd behavior when scrolling.

                          – Jack Giffin
                          Oct 21 '18 at 18:50
















                        • 1





                          Note that in some situations this may not be the case. Firefox 47 reports a textarea clientHeight as 239 while the above equation gives 253 when scrolled to the bottom. Maybe padding/border or something is affecting it? Either way, adding some wiggle room wouldn't hurt, like var isAtBottom = ( logField.scrollHeight - logField.scrollTop <= logField.clientHeight + 50 );. This is useful for auto-scrolling a field only if already at the bottom (so the user can manually examine a specific part of a realtime log without losing their place, etc).

                          – Beejor
                          Aug 19 '16 at 9:30











                        • I would add that it's possible for it to return false negatives as one side could return a small decimal while the other side returns a whole number (eg. 200.181819304947 and 200). I added a Math.floor() to help deal with that but I don't know how reliable this will be.

                          – Hanna
                          Nov 7 '16 at 22:44











                        • For me, this doesn't work cross browser. I get completely different results on chrome compared to firefox.

                          – JedatKinports
                          Dec 20 '16 at 13:45






                        • 1





                          I tried this on the <body> element, and this is firing when the browser is scrolled to the TOP, not the bottom.

                          – Chris Sobolewski
                          Jan 31 '17 at 16:07






                        • 1





                          Math.abs(element.scrollHeight - element.scrollTop - element.clientHeight) <= 3.0 (replace 3.0 with whatever pixel tolerance you think is appropriate for your circumstances). This is the way to go because (A) clientHeight, scrollTop, and clientHeight are all rounded which could potentially lead to a 3px error if all align, (B) 3 pixels is hardly visible to the user so the user may think something is wrong with your site when they "think" they are at the bottom of the page when in fact they are not, and (C) certain devices (especially mouseless ones) can have odd behavior when scrolling.

                          – Jack Giffin
                          Oct 21 '18 at 18:50










                        1




                        1





                        Note that in some situations this may not be the case. Firefox 47 reports a textarea clientHeight as 239 while the above equation gives 253 when scrolled to the bottom. Maybe padding/border or something is affecting it? Either way, adding some wiggle room wouldn't hurt, like var isAtBottom = ( logField.scrollHeight - logField.scrollTop <= logField.clientHeight + 50 );. This is useful for auto-scrolling a field only if already at the bottom (so the user can manually examine a specific part of a realtime log without losing their place, etc).

                        – Beejor
                        Aug 19 '16 at 9:30





                        Note that in some situations this may not be the case. Firefox 47 reports a textarea clientHeight as 239 while the above equation gives 253 when scrolled to the bottom. Maybe padding/border or something is affecting it? Either way, adding some wiggle room wouldn't hurt, like var isAtBottom = ( logField.scrollHeight - logField.scrollTop <= logField.clientHeight + 50 );. This is useful for auto-scrolling a field only if already at the bottom (so the user can manually examine a specific part of a realtime log without losing their place, etc).

                        – Beejor
                        Aug 19 '16 at 9:30













                        I would add that it's possible for it to return false negatives as one side could return a small decimal while the other side returns a whole number (eg. 200.181819304947 and 200). I added a Math.floor() to help deal with that but I don't know how reliable this will be.

                        – Hanna
                        Nov 7 '16 at 22:44





                        I would add that it's possible for it to return false negatives as one side could return a small decimal while the other side returns a whole number (eg. 200.181819304947 and 200). I added a Math.floor() to help deal with that but I don't know how reliable this will be.

                        – Hanna
                        Nov 7 '16 at 22:44













                        For me, this doesn't work cross browser. I get completely different results on chrome compared to firefox.

                        – JedatKinports
                        Dec 20 '16 at 13:45





                        For me, this doesn't work cross browser. I get completely different results on chrome compared to firefox.

                        – JedatKinports
                        Dec 20 '16 at 13:45




                        1




                        1





                        I tried this on the <body> element, and this is firing when the browser is scrolled to the TOP, not the bottom.

                        – Chris Sobolewski
                        Jan 31 '17 at 16:07





                        I tried this on the <body> element, and this is firing when the browser is scrolled to the TOP, not the bottom.

                        – Chris Sobolewski
                        Jan 31 '17 at 16:07




                        1




                        1





                        Math.abs(element.scrollHeight - element.scrollTop - element.clientHeight) <= 3.0 (replace 3.0 with whatever pixel tolerance you think is appropriate for your circumstances). This is the way to go because (A) clientHeight, scrollTop, and clientHeight are all rounded which could potentially lead to a 3px error if all align, (B) 3 pixels is hardly visible to the user so the user may think something is wrong with your site when they "think" they are at the bottom of the page when in fact they are not, and (C) certain devices (especially mouseless ones) can have odd behavior when scrolling.

                        – Jack Giffin
                        Oct 21 '18 at 18:50







                        Math.abs(element.scrollHeight - element.scrollTop - element.clientHeight) <= 3.0 (replace 3.0 with whatever pixel tolerance you think is appropriate for your circumstances). This is the way to go because (A) clientHeight, scrollTop, and clientHeight are all rounded which could potentially lead to a 3px error if all align, (B) 3 pixels is hardly visible to the user so the user may think something is wrong with your site when they "think" they are at the bottom of the page when in fact they are not, and (C) certain devices (especially mouseless ones) can have odd behavior when scrolling.

                        – Jack Giffin
                        Oct 21 '18 at 18:50













                        44














                        For those using Nick's solution and getting repeated alerts / events firing, you could add a line of code above the alert example:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                        $(window).unbind('scroll');
                        alert("near bottom!");
                        }
                        });


                        This means that the code will only fire the first time you're within 100px of the bottom of the document. It won't repeat if you scroll back up and then back down, which may or may not be useful depending on what you're using Nick's code for.






                        share|improve this answer



















                        • 1





                          I would've just commented and said where that line of code is since its relevant to someone else's answer but +1 for the intention!

                          – Nate-Wilkins
                          Oct 1 '12 at 17:07











                        • Sorry, I couldn't (and still can't) see how to add a comment to the answer (like I can here)?

                          – Tim Carr
                          Oct 1 '12 at 19:12











                        • Yea new users can't add a comment to posts unless you get more rep.

                          – Nate-Wilkins
                          Oct 1 '12 at 21:12











                        • Out side the first if you could put a different if that tests if the change you wanted the script to make exists, say a class having been applied to a div. This would make the second nested if not run if it has already run.

                          – fredsbend
                          Jan 31 '13 at 9:06













                        • how can i select particular div id instead of the whole window?

                          – James Smith
                          Mar 23 '15 at 3:28
















                        44














                        For those using Nick's solution and getting repeated alerts / events firing, you could add a line of code above the alert example:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                        $(window).unbind('scroll');
                        alert("near bottom!");
                        }
                        });


                        This means that the code will only fire the first time you're within 100px of the bottom of the document. It won't repeat if you scroll back up and then back down, which may or may not be useful depending on what you're using Nick's code for.






                        share|improve this answer



















                        • 1





                          I would've just commented and said where that line of code is since its relevant to someone else's answer but +1 for the intention!

                          – Nate-Wilkins
                          Oct 1 '12 at 17:07











                        • Sorry, I couldn't (and still can't) see how to add a comment to the answer (like I can here)?

                          – Tim Carr
                          Oct 1 '12 at 19:12











                        • Yea new users can't add a comment to posts unless you get more rep.

                          – Nate-Wilkins
                          Oct 1 '12 at 21:12











                        • Out side the first if you could put a different if that tests if the change you wanted the script to make exists, say a class having been applied to a div. This would make the second nested if not run if it has already run.

                          – fredsbend
                          Jan 31 '13 at 9:06













                        • how can i select particular div id instead of the whole window?

                          – James Smith
                          Mar 23 '15 at 3:28














                        44












                        44








                        44







                        For those using Nick's solution and getting repeated alerts / events firing, you could add a line of code above the alert example:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                        $(window).unbind('scroll');
                        alert("near bottom!");
                        }
                        });


                        This means that the code will only fire the first time you're within 100px of the bottom of the document. It won't repeat if you scroll back up and then back down, which may or may not be useful depending on what you're using Nick's code for.






                        share|improve this answer













                        For those using Nick's solution and getting repeated alerts / events firing, you could add a line of code above the alert example:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                        $(window).unbind('scroll');
                        alert("near bottom!");
                        }
                        });


                        This means that the code will only fire the first time you're within 100px of the bottom of the document. It won't repeat if you scroll back up and then back down, which may or may not be useful depending on what you're using Nick's code for.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Oct 1 '12 at 16:51









                        Tim CarrTim Carr

                        63964




                        63964








                        • 1





                          I would've just commented and said where that line of code is since its relevant to someone else's answer but +1 for the intention!

                          – Nate-Wilkins
                          Oct 1 '12 at 17:07











                        • Sorry, I couldn't (and still can't) see how to add a comment to the answer (like I can here)?

                          – Tim Carr
                          Oct 1 '12 at 19:12











                        • Yea new users can't add a comment to posts unless you get more rep.

                          – Nate-Wilkins
                          Oct 1 '12 at 21:12











                        • Out side the first if you could put a different if that tests if the change you wanted the script to make exists, say a class having been applied to a div. This would make the second nested if not run if it has already run.

                          – fredsbend
                          Jan 31 '13 at 9:06













                        • how can i select particular div id instead of the whole window?

                          – James Smith
                          Mar 23 '15 at 3:28














                        • 1





                          I would've just commented and said where that line of code is since its relevant to someone else's answer but +1 for the intention!

                          – Nate-Wilkins
                          Oct 1 '12 at 17:07











                        • Sorry, I couldn't (and still can't) see how to add a comment to the answer (like I can here)?

                          – Tim Carr
                          Oct 1 '12 at 19:12











                        • Yea new users can't add a comment to posts unless you get more rep.

                          – Nate-Wilkins
                          Oct 1 '12 at 21:12











                        • Out side the first if you could put a different if that tests if the change you wanted the script to make exists, say a class having been applied to a div. This would make the second nested if not run if it has already run.

                          – fredsbend
                          Jan 31 '13 at 9:06













                        • how can i select particular div id instead of the whole window?

                          – James Smith
                          Mar 23 '15 at 3:28








                        1




                        1





                        I would've just commented and said where that line of code is since its relevant to someone else's answer but +1 for the intention!

                        – Nate-Wilkins
                        Oct 1 '12 at 17:07





                        I would've just commented and said where that line of code is since its relevant to someone else's answer but +1 for the intention!

                        – Nate-Wilkins
                        Oct 1 '12 at 17:07













                        Sorry, I couldn't (and still can't) see how to add a comment to the answer (like I can here)?

                        – Tim Carr
                        Oct 1 '12 at 19:12





                        Sorry, I couldn't (and still can't) see how to add a comment to the answer (like I can here)?

                        – Tim Carr
                        Oct 1 '12 at 19:12













                        Yea new users can't add a comment to posts unless you get more rep.

                        – Nate-Wilkins
                        Oct 1 '12 at 21:12





                        Yea new users can't add a comment to posts unless you get more rep.

                        – Nate-Wilkins
                        Oct 1 '12 at 21:12













                        Out side the first if you could put a different if that tests if the change you wanted the script to make exists, say a class having been applied to a div. This would make the second nested if not run if it has already run.

                        – fredsbend
                        Jan 31 '13 at 9:06







                        Out side the first if you could put a different if that tests if the change you wanted the script to make exists, say a class having been applied to a div. This would make the second nested if not run if it has already run.

                        – fredsbend
                        Jan 31 '13 at 9:06















                        how can i select particular div id instead of the whole window?

                        – James Smith
                        Mar 23 '15 at 3:28





                        how can i select particular div id instead of the whole window?

                        – James Smith
                        Mar 23 '15 at 3:28











                        39














                        Further to the excellent accepted answer from Nick Craver, you can throttle the scroll event so that it is not fired so frequently thus increasing browser performance:



                        var _throttleTimer = null;
                        var _throttleDelay = 100;
                        var $window = $(window);
                        var $document = $(document);

                        $document.ready(function () {

                        $window
                        .off('scroll', ScrollHandler)
                        .on('scroll', ScrollHandler);

                        });

                        function ScrollHandler(e) {
                        //throttle event:
                        clearTimeout(_throttleTimer);
                        _throttleTimer = setTimeout(function () {
                        console.log('scroll');

                        //do work
                        if ($window.scrollTop() + $window.height() > $document.height() - 100) {
                        alert("near bottom!");
                        }

                        }, _throttleDelay);
                        }





                        share|improve this answer


























                        • It should probably be pointed out that this requires Underscore.js: underscorejs.org. It's a very good point, though. The scroll event should pretty much always be throttled to avoid serious performance issues.

                          – Jude Osborn
                          Jun 18 '13 at 8:21








                        • 34





                          The above code does NOT require Underscore.js

                          – George Filippakos
                          Jun 19 '13 at 9:03











                        • Maybe it's just me and it could use some benchmarking, but I don't like the idea of invoking clearTimeout and setTimeout on every scroll event. I would issue 1 setTimeout and add some guards in that handler. It's probably just a micro-optimization (if at all).

                          – Grimace of Despair
                          Sep 16 '13 at 14:31











                        • This is a really neat addition! I can think of one further improvement . Currently the function that checks the height wont run if the user continues to scroll. If this is a problem (e.g. you want to trigger the function when the user scrolled half way down regardless of if they keep scrolling) you can easily make sure that the function actually gets called while still prohibiting multiple calls during the chosen interval. Here is a gist to show it. gist.github.com/datacarl/7029558

                          – datacarl
                          Oct 17 '13 at 18:16











                        • What? Invoke a load of machinery to prevent a simple calculation? I don't see how that is more efficient at all

                          – Rambatino
                          Nov 26 '17 at 10:14
















                        39














                        Further to the excellent accepted answer from Nick Craver, you can throttle the scroll event so that it is not fired so frequently thus increasing browser performance:



                        var _throttleTimer = null;
                        var _throttleDelay = 100;
                        var $window = $(window);
                        var $document = $(document);

                        $document.ready(function () {

                        $window
                        .off('scroll', ScrollHandler)
                        .on('scroll', ScrollHandler);

                        });

                        function ScrollHandler(e) {
                        //throttle event:
                        clearTimeout(_throttleTimer);
                        _throttleTimer = setTimeout(function () {
                        console.log('scroll');

                        //do work
                        if ($window.scrollTop() + $window.height() > $document.height() - 100) {
                        alert("near bottom!");
                        }

                        }, _throttleDelay);
                        }





                        share|improve this answer


























                        • It should probably be pointed out that this requires Underscore.js: underscorejs.org. It's a very good point, though. The scroll event should pretty much always be throttled to avoid serious performance issues.

                          – Jude Osborn
                          Jun 18 '13 at 8:21








                        • 34





                          The above code does NOT require Underscore.js

                          – George Filippakos
                          Jun 19 '13 at 9:03











                        • Maybe it's just me and it could use some benchmarking, but I don't like the idea of invoking clearTimeout and setTimeout on every scroll event. I would issue 1 setTimeout and add some guards in that handler. It's probably just a micro-optimization (if at all).

                          – Grimace of Despair
                          Sep 16 '13 at 14:31











                        • This is a really neat addition! I can think of one further improvement . Currently the function that checks the height wont run if the user continues to scroll. If this is a problem (e.g. you want to trigger the function when the user scrolled half way down regardless of if they keep scrolling) you can easily make sure that the function actually gets called while still prohibiting multiple calls during the chosen interval. Here is a gist to show it. gist.github.com/datacarl/7029558

                          – datacarl
                          Oct 17 '13 at 18:16











                        • What? Invoke a load of machinery to prevent a simple calculation? I don't see how that is more efficient at all

                          – Rambatino
                          Nov 26 '17 at 10:14














                        39












                        39








                        39







                        Further to the excellent accepted answer from Nick Craver, you can throttle the scroll event so that it is not fired so frequently thus increasing browser performance:



                        var _throttleTimer = null;
                        var _throttleDelay = 100;
                        var $window = $(window);
                        var $document = $(document);

                        $document.ready(function () {

                        $window
                        .off('scroll', ScrollHandler)
                        .on('scroll', ScrollHandler);

                        });

                        function ScrollHandler(e) {
                        //throttle event:
                        clearTimeout(_throttleTimer);
                        _throttleTimer = setTimeout(function () {
                        console.log('scroll');

                        //do work
                        if ($window.scrollTop() + $window.height() > $document.height() - 100) {
                        alert("near bottom!");
                        }

                        }, _throttleDelay);
                        }





                        share|improve this answer















                        Further to the excellent accepted answer from Nick Craver, you can throttle the scroll event so that it is not fired so frequently thus increasing browser performance:



                        var _throttleTimer = null;
                        var _throttleDelay = 100;
                        var $window = $(window);
                        var $document = $(document);

                        $document.ready(function () {

                        $window
                        .off('scroll', ScrollHandler)
                        .on('scroll', ScrollHandler);

                        });

                        function ScrollHandler(e) {
                        //throttle event:
                        clearTimeout(_throttleTimer);
                        _throttleTimer = setTimeout(function () {
                        console.log('scroll');

                        //do work
                        if ($window.scrollTop() + $window.height() > $document.height() - 100) {
                        alert("near bottom!");
                        }

                        }, _throttleDelay);
                        }






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Feb 19 '14 at 7:11

























                        answered Mar 13 '13 at 10:22









                        George FilippakosGeorge Filippakos

                        11.4k86678




                        11.4k86678













                        • It should probably be pointed out that this requires Underscore.js: underscorejs.org. It's a very good point, though. The scroll event should pretty much always be throttled to avoid serious performance issues.

                          – Jude Osborn
                          Jun 18 '13 at 8:21








                        • 34





                          The above code does NOT require Underscore.js

                          – George Filippakos
                          Jun 19 '13 at 9:03











                        • Maybe it's just me and it could use some benchmarking, but I don't like the idea of invoking clearTimeout and setTimeout on every scroll event. I would issue 1 setTimeout and add some guards in that handler. It's probably just a micro-optimization (if at all).

                          – Grimace of Despair
                          Sep 16 '13 at 14:31











                        • This is a really neat addition! I can think of one further improvement . Currently the function that checks the height wont run if the user continues to scroll. If this is a problem (e.g. you want to trigger the function when the user scrolled half way down regardless of if they keep scrolling) you can easily make sure that the function actually gets called while still prohibiting multiple calls during the chosen interval. Here is a gist to show it. gist.github.com/datacarl/7029558

                          – datacarl
                          Oct 17 '13 at 18:16











                        • What? Invoke a load of machinery to prevent a simple calculation? I don't see how that is more efficient at all

                          – Rambatino
                          Nov 26 '17 at 10:14



















                        • It should probably be pointed out that this requires Underscore.js: underscorejs.org. It's a very good point, though. The scroll event should pretty much always be throttled to avoid serious performance issues.

                          – Jude Osborn
                          Jun 18 '13 at 8:21








                        • 34





                          The above code does NOT require Underscore.js

                          – George Filippakos
                          Jun 19 '13 at 9:03











                        • Maybe it's just me and it could use some benchmarking, but I don't like the idea of invoking clearTimeout and setTimeout on every scroll event. I would issue 1 setTimeout and add some guards in that handler. It's probably just a micro-optimization (if at all).

                          – Grimace of Despair
                          Sep 16 '13 at 14:31











                        • This is a really neat addition! I can think of one further improvement . Currently the function that checks the height wont run if the user continues to scroll. If this is a problem (e.g. you want to trigger the function when the user scrolled half way down regardless of if they keep scrolling) you can easily make sure that the function actually gets called while still prohibiting multiple calls during the chosen interval. Here is a gist to show it. gist.github.com/datacarl/7029558

                          – datacarl
                          Oct 17 '13 at 18:16











                        • What? Invoke a load of machinery to prevent a simple calculation? I don't see how that is more efficient at all

                          – Rambatino
                          Nov 26 '17 at 10:14

















                        It should probably be pointed out that this requires Underscore.js: underscorejs.org. It's a very good point, though. The scroll event should pretty much always be throttled to avoid serious performance issues.

                        – Jude Osborn
                        Jun 18 '13 at 8:21







                        It should probably be pointed out that this requires Underscore.js: underscorejs.org. It's a very good point, though. The scroll event should pretty much always be throttled to avoid serious performance issues.

                        – Jude Osborn
                        Jun 18 '13 at 8:21






                        34




                        34





                        The above code does NOT require Underscore.js

                        – George Filippakos
                        Jun 19 '13 at 9:03





                        The above code does NOT require Underscore.js

                        – George Filippakos
                        Jun 19 '13 at 9:03













                        Maybe it's just me and it could use some benchmarking, but I don't like the idea of invoking clearTimeout and setTimeout on every scroll event. I would issue 1 setTimeout and add some guards in that handler. It's probably just a micro-optimization (if at all).

                        – Grimace of Despair
                        Sep 16 '13 at 14:31





                        Maybe it's just me and it could use some benchmarking, but I don't like the idea of invoking clearTimeout and setTimeout on every scroll event. I would issue 1 setTimeout and add some guards in that handler. It's probably just a micro-optimization (if at all).

                        – Grimace of Despair
                        Sep 16 '13 at 14:31













                        This is a really neat addition! I can think of one further improvement . Currently the function that checks the height wont run if the user continues to scroll. If this is a problem (e.g. you want to trigger the function when the user scrolled half way down regardless of if they keep scrolling) you can easily make sure that the function actually gets called while still prohibiting multiple calls during the chosen interval. Here is a gist to show it. gist.github.com/datacarl/7029558

                        – datacarl
                        Oct 17 '13 at 18:16





                        This is a really neat addition! I can think of one further improvement . Currently the function that checks the height wont run if the user continues to scroll. If this is a problem (e.g. you want to trigger the function when the user scrolled half way down regardless of if they keep scrolling) you can easily make sure that the function actually gets called while still prohibiting multiple calls during the chosen interval. Here is a gist to show it. gist.github.com/datacarl/7029558

                        – datacarl
                        Oct 17 '13 at 18:16













                        What? Invoke a load of machinery to prevent a simple calculation? I don't see how that is more efficient at all

                        – Rambatino
                        Nov 26 '17 at 10:14





                        What? Invoke a load of machinery to prevent a simple calculation? I don't see how that is more efficient at all

                        – Rambatino
                        Nov 26 '17 at 10:14











                        35














                        Nick Craver's answer needs to be slightly modified to work on iOS 6 Safari Mobile and should be:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + window.innerHeight == $(document).height()) {
                        alert("bottom!");
                        }
                        });


                        Changing $(window).height() to window.innerHeight should be done because when the address bar is hidden an additional 60px are added to the window's height but using $(window).height() does not reflect this change, while using window.innerHeight does.



                        Note: The window.innerHeight property also includes the horizontal scrollbar's height (if it is rendered), unlike $(window).height() which will not include the horizontal scrollbar's height. This is not a problem in Mobile Safari, but could cause unexpected behavior in other browsers or future versions of Mobile Safari. Changing == to >= could fix this for most common use cases.



                        Read more about the window.innerHeight property here






                        share|improve this answer


























                        • window.innerHeight made more sense for what i was trying to accomplish thanks!

                          – Amir5000
                          Sep 18 '14 at 17:36











                        • How to get remaining height after scroll?

                          – OPV
                          Aug 25 '18 at 0:46
















                        35














                        Nick Craver's answer needs to be slightly modified to work on iOS 6 Safari Mobile and should be:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + window.innerHeight == $(document).height()) {
                        alert("bottom!");
                        }
                        });


                        Changing $(window).height() to window.innerHeight should be done because when the address bar is hidden an additional 60px are added to the window's height but using $(window).height() does not reflect this change, while using window.innerHeight does.



                        Note: The window.innerHeight property also includes the horizontal scrollbar's height (if it is rendered), unlike $(window).height() which will not include the horizontal scrollbar's height. This is not a problem in Mobile Safari, but could cause unexpected behavior in other browsers or future versions of Mobile Safari. Changing == to >= could fix this for most common use cases.



                        Read more about the window.innerHeight property here






                        share|improve this answer


























                        • window.innerHeight made more sense for what i was trying to accomplish thanks!

                          – Amir5000
                          Sep 18 '14 at 17:36











                        • How to get remaining height after scroll?

                          – OPV
                          Aug 25 '18 at 0:46














                        35












                        35








                        35







                        Nick Craver's answer needs to be slightly modified to work on iOS 6 Safari Mobile and should be:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + window.innerHeight == $(document).height()) {
                        alert("bottom!");
                        }
                        });


                        Changing $(window).height() to window.innerHeight should be done because when the address bar is hidden an additional 60px are added to the window's height but using $(window).height() does not reflect this change, while using window.innerHeight does.



                        Note: The window.innerHeight property also includes the horizontal scrollbar's height (if it is rendered), unlike $(window).height() which will not include the horizontal scrollbar's height. This is not a problem in Mobile Safari, but could cause unexpected behavior in other browsers or future versions of Mobile Safari. Changing == to >= could fix this for most common use cases.



                        Read more about the window.innerHeight property here






                        share|improve this answer















                        Nick Craver's answer needs to be slightly modified to work on iOS 6 Safari Mobile and should be:



                        $(window).scroll(function() {
                        if($(window).scrollTop() + window.innerHeight == $(document).height()) {
                        alert("bottom!");
                        }
                        });


                        Changing $(window).height() to window.innerHeight should be done because when the address bar is hidden an additional 60px are added to the window's height but using $(window).height() does not reflect this change, while using window.innerHeight does.



                        Note: The window.innerHeight property also includes the horizontal scrollbar's height (if it is rendered), unlike $(window).height() which will not include the horizontal scrollbar's height. This is not a problem in Mobile Safari, but could cause unexpected behavior in other browsers or future versions of Mobile Safari. Changing == to >= could fix this for most common use cases.



                        Read more about the window.innerHeight property here







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Mar 6 '15 at 16:53









                        Liam

                        16.2k1676129




                        16.2k1676129










                        answered Jul 3 '13 at 14:31









                        YosiYosi

                        620618




                        620618













                        • window.innerHeight made more sense for what i was trying to accomplish thanks!

                          – Amir5000
                          Sep 18 '14 at 17:36











                        • How to get remaining height after scroll?

                          – OPV
                          Aug 25 '18 at 0:46



















                        • window.innerHeight made more sense for what i was trying to accomplish thanks!

                          – Amir5000
                          Sep 18 '14 at 17:36











                        • How to get remaining height after scroll?

                          – OPV
                          Aug 25 '18 at 0:46

















                        window.innerHeight made more sense for what i was trying to accomplish thanks!

                        – Amir5000
                        Sep 18 '14 at 17:36





                        window.innerHeight made more sense for what i was trying to accomplish thanks!

                        – Amir5000
                        Sep 18 '14 at 17:36













                        How to get remaining height after scroll?

                        – OPV
                        Aug 25 '18 at 0:46





                        How to get remaining height after scroll?

                        – OPV
                        Aug 25 '18 at 0:46











                        18














                        Here's a fairly simple approach:



                        elm.onscroll = function() {
                        if(elm.scrollTop + elm.clientHeight == elm.scrollHeight) //User has scrolled to the bottom of the element
                        }





                        share|improve this answer






























                          18














                          Here's a fairly simple approach:



                          elm.onscroll = function() {
                          if(elm.scrollTop + elm.clientHeight == elm.scrollHeight) //User has scrolled to the bottom of the element
                          }





                          share|improve this answer




























                            18












                            18








                            18







                            Here's a fairly simple approach:



                            elm.onscroll = function() {
                            if(elm.scrollTop + elm.clientHeight == elm.scrollHeight) //User has scrolled to the bottom of the element
                            }





                            share|improve this answer















                            Here's a fairly simple approach:



                            elm.onscroll = function() {
                            if(elm.scrollTop + elm.clientHeight == elm.scrollHeight) //User has scrolled to the bottom of the element
                            }






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jun 24 '17 at 14:00

























                            answered Mar 9 '16 at 10:19









                            Frederik WitteFrederik Witte

                            5021925




                            5021925























                                14














                                Here is a piece of code that will help you debug your code, I tested the above answers and found them to be buggy. I have test the followings on Chrome, IE, Firefox, IPad(Safari). I don't have any others installed to test...



                                <script type="text/javascript">
                                $(function() {
                                $(window).scroll(function () {
                                var docElement = $(document)[0].documentElement;
                                var winElement = $(window)[0];

                                if ((docElement.scrollHeight - winElement.innerHeight) == winElement.pageYOffset) {
                                alert('bottom');
                                }
                                });
                                });
                                </script>


                                There may be a simpler solution, but I stopped at the point at which IT WORKED



                                If you are still having problems with some rogue browser, here is some code to help you debug:



                                <script type="text/javascript">
                                $(function() {
                                $(window).scroll(function () {
                                var docElement = $(document)[0].documentElement;
                                var details = "";
                                details += '<b>Document</b><br />';
                                details += 'clientHeight:' + docElement.clientHeight + '<br />';
                                details += 'clientTop:' + docElement.clientTop + '<br />';
                                details += 'offsetHeight:' + docElement.offsetHeight + '<br />';
                                details += 'offsetParent:' + (docElement.offsetParent == null) + '<br />';
                                details += 'scrollHeight:' + docElement.scrollHeight + '<br />';
                                details += 'scrollTop:' + docElement.scrollTop + '<br />';

                                var winElement = $(window)[0];
                                details += '<b>Window</b><br />';
                                details += 'innerHeight:' + winElement.innerHeight + '<br />';
                                details += 'outerHeight:' + winElement.outerHeight + '<br />';
                                details += 'pageYOffset:' + winElement.pageYOffset + '<br />';
                                details += 'screenTop:' + winElement.screenTop + '<br />';
                                details += 'screenY:' + winElement.screenY + '<br />';
                                details += 'scrollY:' + winElement.scrollY + '<br />';

                                details += '<b>End of page</b><br />';
                                details += 'Test:' + (docElement.scrollHeight - winElement.innerHeight) + '=' + winElement.pageYOffset + '<br />';
                                details += 'End of Page? ';
                                if ((docElement.scrollHeight - winElement.innerHeight) == winElement.pageYOffset) {
                                details += 'YES';
                                } else {
                                details += 'NO';
                                }

                                $('#test').html(details);
                                });
                                });
                                </script>
                                <div id="test" style="position: fixed; left:0; top: 0; z-index: 9999; background-color: #FFFFFF;">


                                I hope this will save someone some time.






                                share|improve this answer


























                                • Best answer for Vanilla js, No jQuery solution. Use var docElement = document.documentElement; var winElement = window

                                  – jperelli
                                  Jun 22 '16 at 15:04
















                                14














                                Here is a piece of code that will help you debug your code, I tested the above answers and found them to be buggy. I have test the followings on Chrome, IE, Firefox, IPad(Safari). I don't have any others installed to test...



                                <script type="text/javascript">
                                $(function() {
                                $(window).scroll(function () {
                                var docElement = $(document)[0].documentElement;
                                var winElement = $(window)[0];

                                if ((docElement.scrollHeight - winElement.innerHeight) == winElement.pageYOffset) {
                                alert('bottom');
                                }
                                });
                                });
                                </script>


                                There may be a simpler solution, but I stopped at the point at which IT WORKED



                                If you are still having problems with some rogue browser, here is some code to help you debug:



                                <script type="text/javascript">
                                $(function() {
                                $(window).scroll(function () {
                                var docElement = $(document)[0].documentElement;
                                var details = "";
                                details += '<b>Document</b><br />';
                                details += 'clientHeight:' + docElement.clientHeight + '<br />';
                                details += 'clientTop:' + docElement.clientTop + '<br />';
                                details += 'offsetHeight:' + docElement.offsetHeight + '<br />';
                                details += 'offsetParent:' + (docElement.offsetParent == null) + '<br />';
                                details += 'scrollHeight:' + docElement.scrollHeight + '<br />';
                                details += 'scrollTop:' + docElement.scrollTop + '<br />';

                                var winElement = $(window)[0];
                                details += '<b>Window</b><br />';
                                details += 'innerHeight:' + winElement.innerHeight + '<br />';
                                details += 'outerHeight:' + winElement.outerHeight + '<br />';
                                details += 'pageYOffset:' + winElement.pageYOffset + '<br />';
                                details += 'screenTop:' + winElement.screenTop + '<br />';
                                details += 'screenY:' + winElement.screenY + '<br />';
                                details += 'scrollY:' + winElement.scrollY + '<br />';

                                details += '<b>End of page</b><br />';
                                details += 'Test:' + (docElement.scrollHeight - winElement.innerHeight) + '=' + winElement.pageYOffset + '<br />';
                                details += 'End of Page? ';
                                if ((docElement.scrollHeight - winElement.innerHeight) == winElement.pageYOffset) {
                                details += 'YES';
                                } else {
                                details += 'NO';
                                }

                                $('#test').html(details);
                                });
                                });
                                </script>
                                <div id="test" style="position: fixed; left:0; top: 0; z-index: 9999; background-color: #FFFFFF;">


                                I hope this will save someone some time.






                                share|improve this answer


























                                • Best answer for Vanilla js, No jQuery solution. Use var docElement = document.documentElement; var winElement = window

                                  – jperelli
                                  Jun 22 '16 at 15:04














                                14












                                14








                                14







                                Here is a piece of code that will help you debug your code, I tested the above answers and found them to be buggy. I have test the followings on Chrome, IE, Firefox, IPad(Safari). I don't have any others installed to test...



                                <script type="text/javascript">
                                $(function() {
                                $(window).scroll(function () {
                                var docElement = $(document)[0].documentElement;
                                var winElement = $(window)[0];

                                if ((docElement.scrollHeight - winElement.innerHeight) == winElement.pageYOffset) {
                                alert('bottom');
                                }
                                });
                                });
                                </script>


                                There may be a simpler solution, but I stopped at the point at which IT WORKED



                                If you are still having problems with some rogue browser, here is some code to help you debug:



                                <script type="text/javascript">
                                $(function() {
                                $(window).scroll(function () {
                                var docElement = $(document)[0].documentElement;
                                var details = "";
                                details += '<b>Document</b><br />';
                                details += 'clientHeight:' + docElement.clientHeight + '<br />';
                                details += 'clientTop:' + docElement.clientTop + '<br />';
                                details += 'offsetHeight:' + docElement.offsetHeight + '<br />';
                                details += 'offsetParent:' + (docElement.offsetParent == null) + '<br />';
                                details += 'scrollHeight:' + docElement.scrollHeight + '<br />';
                                details += 'scrollTop:' + docElement.scrollTop + '<br />';

                                var winElement = $(window)[0];
                                details += '<b>Window</b><br />';
                                details += 'innerHeight:' + winElement.innerHeight + '<br />';
                                details += 'outerHeight:' + winElement.outerHeight + '<br />';
                                details += 'pageYOffset:' + winElement.pageYOffset + '<br />';
                                details += 'screenTop:' + winElement.screenTop + '<br />';
                                details += 'screenY:' + winElement.screenY + '<br />';
                                details += 'scrollY:' + winElement.scrollY + '<br />';

                                details += '<b>End of page</b><br />';
                                details += 'Test:' + (docElement.scrollHeight - winElement.innerHeight) + '=' + winElement.pageYOffset + '<br />';
                                details += 'End of Page? ';
                                if ((docElement.scrollHeight - winElement.innerHeight) == winElement.pageYOffset) {
                                details += 'YES';
                                } else {
                                details += 'NO';
                                }

                                $('#test').html(details);
                                });
                                });
                                </script>
                                <div id="test" style="position: fixed; left:0; top: 0; z-index: 9999; background-color: #FFFFFF;">


                                I hope this will save someone some time.






                                share|improve this answer















                                Here is a piece of code that will help you debug your code, I tested the above answers and found them to be buggy. I have test the followings on Chrome, IE, Firefox, IPad(Safari). I don't have any others installed to test...



                                <script type="text/javascript">
                                $(function() {
                                $(window).scroll(function () {
                                var docElement = $(document)[0].documentElement;
                                var winElement = $(window)[0];

                                if ((docElement.scrollHeight - winElement.innerHeight) == winElement.pageYOffset) {
                                alert('bottom');
                                }
                                });
                                });
                                </script>


                                There may be a simpler solution, but I stopped at the point at which IT WORKED



                                If you are still having problems with some rogue browser, here is some code to help you debug:



                                <script type="text/javascript">
                                $(function() {
                                $(window).scroll(function () {
                                var docElement = $(document)[0].documentElement;
                                var details = "";
                                details += '<b>Document</b><br />';
                                details += 'clientHeight:' + docElement.clientHeight + '<br />';
                                details += 'clientTop:' + docElement.clientTop + '<br />';
                                details += 'offsetHeight:' + docElement.offsetHeight + '<br />';
                                details += 'offsetParent:' + (docElement.offsetParent == null) + '<br />';
                                details += 'scrollHeight:' + docElement.scrollHeight + '<br />';
                                details += 'scrollTop:' + docElement.scrollTop + '<br />';

                                var winElement = $(window)[0];
                                details += '<b>Window</b><br />';
                                details += 'innerHeight:' + winElement.innerHeight + '<br />';
                                details += 'outerHeight:' + winElement.outerHeight + '<br />';
                                details += 'pageYOffset:' + winElement.pageYOffset + '<br />';
                                details += 'screenTop:' + winElement.screenTop + '<br />';
                                details += 'screenY:' + winElement.screenY + '<br />';
                                details += 'scrollY:' + winElement.scrollY + '<br />';

                                details += '<b>End of page</b><br />';
                                details += 'Test:' + (docElement.scrollHeight - winElement.innerHeight) + '=' + winElement.pageYOffset + '<br />';
                                details += 'End of Page? ';
                                if ((docElement.scrollHeight - winElement.innerHeight) == winElement.pageYOffset) {
                                details += 'YES';
                                } else {
                                details += 'NO';
                                }

                                $('#test').html(details);
                                });
                                });
                                </script>
                                <div id="test" style="position: fixed; left:0; top: 0; z-index: 9999; background-color: #FFFFFF;">


                                I hope this will save someone some time.







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Jan 5 '16 at 18:56









                                Peter Hall

                                15.7k74186




                                15.7k74186










                                answered Feb 19 '14 at 9:52









                                TalonTalon

                                2,43422039




                                2,43422039













                                • Best answer for Vanilla js, No jQuery solution. Use var docElement = document.documentElement; var winElement = window

                                  – jperelli
                                  Jun 22 '16 at 15:04



















                                • Best answer for Vanilla js, No jQuery solution. Use var docElement = document.documentElement; var winElement = window

                                  – jperelli
                                  Jun 22 '16 at 15:04

















                                Best answer for Vanilla js, No jQuery solution. Use var docElement = document.documentElement; var winElement = window

                                – jperelli
                                Jun 22 '16 at 15:04





                                Best answer for Vanilla js, No jQuery solution. Use var docElement = document.documentElement; var winElement = window

                                – jperelli
                                Jun 22 '16 at 15:04











                                10














                                Please check this answer



                                 window.onscroll = function(ev) {
                                if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
                                console.log("bottom");
                                }
                                };


                                You can do footerHeight - document.body.offsetHeight to see if you are near the footer or reached the footer






                                share|improve this answer






























                                  10














                                  Please check this answer



                                   window.onscroll = function(ev) {
                                  if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
                                  console.log("bottom");
                                  }
                                  };


                                  You can do footerHeight - document.body.offsetHeight to see if you are near the footer or reached the footer






                                  share|improve this answer




























                                    10












                                    10








                                    10







                                    Please check this answer



                                     window.onscroll = function(ev) {
                                    if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
                                    console.log("bottom");
                                    }
                                    };


                                    You can do footerHeight - document.body.offsetHeight to see if you are near the footer or reached the footer






                                    share|improve this answer















                                    Please check this answer



                                     window.onscroll = function(ev) {
                                    if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
                                    console.log("bottom");
                                    }
                                    };


                                    You can do footerHeight - document.body.offsetHeight to see if you are near the footer or reached the footer







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited May 23 '17 at 12:18









                                    Community

                                    11




                                    11










                                    answered Jan 2 '16 at 7:09









                                    Junaid QadirJunaid Qadir

                                    79811332




                                    79811332























                                        10














                                        var elemScrolPosition = elem.scrollHeight - elem.scrollTop - elem.clientHeight;


                                        It calculates distance scroll bar to bottom of element.
                                        Equal 0, if scroll bar has reached bottom.






                                        share|improve this answer



















                                        • 1





                                          I did the following and worked flawlessly. Thanks. var shouldScroll = (elem.scrollHeight - elem.scrollTop - elem.clientHeight) == 0;

                                          – jiminssy
                                          Nov 20 '16 at 16:48


















                                        10














                                        var elemScrolPosition = elem.scrollHeight - elem.scrollTop - elem.clientHeight;


                                        It calculates distance scroll bar to bottom of element.
                                        Equal 0, if scroll bar has reached bottom.






                                        share|improve this answer



















                                        • 1





                                          I did the following and worked flawlessly. Thanks. var shouldScroll = (elem.scrollHeight - elem.scrollTop - elem.clientHeight) == 0;

                                          – jiminssy
                                          Nov 20 '16 at 16:48
















                                        10












                                        10








                                        10







                                        var elemScrolPosition = elem.scrollHeight - elem.scrollTop - elem.clientHeight;


                                        It calculates distance scroll bar to bottom of element.
                                        Equal 0, if scroll bar has reached bottom.






                                        share|improve this answer













                                        var elemScrolPosition = elem.scrollHeight - elem.scrollTop - elem.clientHeight;


                                        It calculates distance scroll bar to bottom of element.
                                        Equal 0, if scroll bar has reached bottom.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Nov 12 '16 at 22:13









                                        Vasyl GutnykVasyl Gutnyk

                                        2,55621725




                                        2,55621725








                                        • 1





                                          I did the following and worked flawlessly. Thanks. var shouldScroll = (elem.scrollHeight - elem.scrollTop - elem.clientHeight) == 0;

                                          – jiminssy
                                          Nov 20 '16 at 16:48
















                                        • 1





                                          I did the following and worked flawlessly. Thanks. var shouldScroll = (elem.scrollHeight - elem.scrollTop - elem.clientHeight) == 0;

                                          – jiminssy
                                          Nov 20 '16 at 16:48










                                        1




                                        1





                                        I did the following and worked flawlessly. Thanks. var shouldScroll = (elem.scrollHeight - elem.scrollTop - elem.clientHeight) == 0;

                                        – jiminssy
                                        Nov 20 '16 at 16:48







                                        I did the following and worked flawlessly. Thanks. var shouldScroll = (elem.scrollHeight - elem.scrollTop - elem.clientHeight) == 0;

                                        – jiminssy
                                        Nov 20 '16 at 16:48













                                        9














                                        This is my two cents:



                                        $('#container_element').scroll( function(){
                                        console.log($(this).scrollTop()+' + '+ $(this).height()+' = '+ ($(this).scrollTop() + $(this).height()) +' _ '+ $(this)[0].scrollHeight );
                                        if($(this).scrollTop() + $(this).height() == $(this)[0].scrollHeight){
                                        console.log('bottom found');
                                        }
                                        });





                                        share|improve this answer




























                                          9














                                          This is my two cents:



                                          $('#container_element').scroll( function(){
                                          console.log($(this).scrollTop()+' + '+ $(this).height()+' = '+ ($(this).scrollTop() + $(this).height()) +' _ '+ $(this)[0].scrollHeight );
                                          if($(this).scrollTop() + $(this).height() == $(this)[0].scrollHeight){
                                          console.log('bottom found');
                                          }
                                          });





                                          share|improve this answer


























                                            9












                                            9








                                            9







                                            This is my two cents:



                                            $('#container_element').scroll( function(){
                                            console.log($(this).scrollTop()+' + '+ $(this).height()+' = '+ ($(this).scrollTop() + $(this).height()) +' _ '+ $(this)[0].scrollHeight );
                                            if($(this).scrollTop() + $(this).height() == $(this)[0].scrollHeight){
                                            console.log('bottom found');
                                            }
                                            });





                                            share|improve this answer













                                            This is my two cents:



                                            $('#container_element').scroll( function(){
                                            console.log($(this).scrollTop()+' + '+ $(this).height()+' = '+ ($(this).scrollTop() + $(this).height()) +' _ '+ $(this)[0].scrollHeight );
                                            if($(this).scrollTop() + $(this).height() == $(this)[0].scrollHeight){
                                            console.log('bottom found');
                                            }
                                            });






                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Nov 25 '15 at 1:22









                                            ddanoneddanone

                                            33036




                                            33036























                                                5














                                                Pure JS with cross-browser and debouncing (Pretty good performance)



                                                var CheckIfScrollBottom = debouncer(function() {
                                                if(getDocHeight() == getScrollXY()[1] + window.innerHeight) {
                                                console.log('Bottom!');
                                                }
                                                },500);

                                                document.addEventListener('scroll',CheckIfScrollBottom);

                                                function debouncer(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}
                                                function getScrollXY(){var a=0,b=0;return"number"==typeof window.pageYOffset?(b=window.pageYOffset,a=window.pageXOffset):document.body&&(document.body.scrollLeft||document.body.scrollTop)?(b=document.body.scrollTop,a=document.body.scrollLeft):document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)&&(b=document.documentElement.scrollTop,a=document.documentElement.scrollLeft),[a,b]}
                                                function getDocHeight(){var a=document;return Math.max(a.body.scrollHeight,a.documentElement.scrollHeight,a.body.offsetHeight,a.documentElement.offsetHeight,a.body.clientHeight,a.documentElement.clientHeight)}


                                                Demo : http://jsbin.com/geherovena/edit?js,output



                                                PS: Debouncer, getScrollXY, getDocHeight not written by me



                                                I just show how its work, And how I will do






                                                share|improve this answer


























                                                • Perfect. Tested in Firefox and Chrome

                                                  – Erlisar Vasquez
                                                  Nov 23 '18 at 3:14


















                                                5














                                                Pure JS with cross-browser and debouncing (Pretty good performance)



                                                var CheckIfScrollBottom = debouncer(function() {
                                                if(getDocHeight() == getScrollXY()[1] + window.innerHeight) {
                                                console.log('Bottom!');
                                                }
                                                },500);

                                                document.addEventListener('scroll',CheckIfScrollBottom);

                                                function debouncer(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}
                                                function getScrollXY(){var a=0,b=0;return"number"==typeof window.pageYOffset?(b=window.pageYOffset,a=window.pageXOffset):document.body&&(document.body.scrollLeft||document.body.scrollTop)?(b=document.body.scrollTop,a=document.body.scrollLeft):document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)&&(b=document.documentElement.scrollTop,a=document.documentElement.scrollLeft),[a,b]}
                                                function getDocHeight(){var a=document;return Math.max(a.body.scrollHeight,a.documentElement.scrollHeight,a.body.offsetHeight,a.documentElement.offsetHeight,a.body.clientHeight,a.documentElement.clientHeight)}


                                                Demo : http://jsbin.com/geherovena/edit?js,output



                                                PS: Debouncer, getScrollXY, getDocHeight not written by me



                                                I just show how its work, And how I will do






                                                share|improve this answer


























                                                • Perfect. Tested in Firefox and Chrome

                                                  – Erlisar Vasquez
                                                  Nov 23 '18 at 3:14
















                                                5












                                                5








                                                5







                                                Pure JS with cross-browser and debouncing (Pretty good performance)



                                                var CheckIfScrollBottom = debouncer(function() {
                                                if(getDocHeight() == getScrollXY()[1] + window.innerHeight) {
                                                console.log('Bottom!');
                                                }
                                                },500);

                                                document.addEventListener('scroll',CheckIfScrollBottom);

                                                function debouncer(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}
                                                function getScrollXY(){var a=0,b=0;return"number"==typeof window.pageYOffset?(b=window.pageYOffset,a=window.pageXOffset):document.body&&(document.body.scrollLeft||document.body.scrollTop)?(b=document.body.scrollTop,a=document.body.scrollLeft):document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)&&(b=document.documentElement.scrollTop,a=document.documentElement.scrollLeft),[a,b]}
                                                function getDocHeight(){var a=document;return Math.max(a.body.scrollHeight,a.documentElement.scrollHeight,a.body.offsetHeight,a.documentElement.offsetHeight,a.body.clientHeight,a.documentElement.clientHeight)}


                                                Demo : http://jsbin.com/geherovena/edit?js,output



                                                PS: Debouncer, getScrollXY, getDocHeight not written by me



                                                I just show how its work, And how I will do






                                                share|improve this answer















                                                Pure JS with cross-browser and debouncing (Pretty good performance)



                                                var CheckIfScrollBottom = debouncer(function() {
                                                if(getDocHeight() == getScrollXY()[1] + window.innerHeight) {
                                                console.log('Bottom!');
                                                }
                                                },500);

                                                document.addEventListener('scroll',CheckIfScrollBottom);

                                                function debouncer(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}
                                                function getScrollXY(){var a=0,b=0;return"number"==typeof window.pageYOffset?(b=window.pageYOffset,a=window.pageXOffset):document.body&&(document.body.scrollLeft||document.body.scrollTop)?(b=document.body.scrollTop,a=document.body.scrollLeft):document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)&&(b=document.documentElement.scrollTop,a=document.documentElement.scrollLeft),[a,b]}
                                                function getDocHeight(){var a=document;return Math.max(a.body.scrollHeight,a.documentElement.scrollHeight,a.body.offsetHeight,a.documentElement.offsetHeight,a.body.clientHeight,a.documentElement.clientHeight)}


                                                Demo : http://jsbin.com/geherovena/edit?js,output



                                                PS: Debouncer, getScrollXY, getDocHeight not written by me



                                                I just show how its work, And how I will do







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Feb 1 '17 at 8:35

























                                                answered Nov 17 '15 at 10:02









                                                l2aelbal2aelba

                                                10.5k1474109




                                                10.5k1474109













                                                • Perfect. Tested in Firefox and Chrome

                                                  – Erlisar Vasquez
                                                  Nov 23 '18 at 3:14





















                                                • Perfect. Tested in Firefox and Chrome

                                                  – Erlisar Vasquez
                                                  Nov 23 '18 at 3:14



















                                                Perfect. Tested in Firefox and Chrome

                                                – Erlisar Vasquez
                                                Nov 23 '18 at 3:14







                                                Perfect. Tested in Firefox and Chrome

                                                – Erlisar Vasquez
                                                Nov 23 '18 at 3:14













                                                2














                                                Nick answers its fine but you will have functions which repeats itsself while scrolling or will not work at all if user has the window zoomed. I came up with an easy fix just math.round the first height and it works just as assumed.



                                                    if (Math.round($(window).scrollTop()) + $(window).innerHeight() == $(document).height()){
                                                loadPagination();
                                                $(".go-up").css("display","block").show("slow");
                                                }





                                                share|improve this answer




























                                                  2














                                                  Nick answers its fine but you will have functions which repeats itsself while scrolling or will not work at all if user has the window zoomed. I came up with an easy fix just math.round the first height and it works just as assumed.



                                                      if (Math.round($(window).scrollTop()) + $(window).innerHeight() == $(document).height()){
                                                  loadPagination();
                                                  $(".go-up").css("display","block").show("slow");
                                                  }





                                                  share|improve this answer


























                                                    2












                                                    2








                                                    2







                                                    Nick answers its fine but you will have functions which repeats itsself while scrolling or will not work at all if user has the window zoomed. I came up with an easy fix just math.round the first height and it works just as assumed.



                                                        if (Math.round($(window).scrollTop()) + $(window).innerHeight() == $(document).height()){
                                                    loadPagination();
                                                    $(".go-up").css("display","block").show("slow");
                                                    }





                                                    share|improve this answer













                                                    Nick answers its fine but you will have functions which repeats itsself while scrolling or will not work at all if user has the window zoomed. I came up with an easy fix just math.round the first height and it works just as assumed.



                                                        if (Math.round($(window).scrollTop()) + $(window).innerHeight() == $(document).height()){
                                                    loadPagination();
                                                    $(".go-up").css("display","block").show("slow");
                                                    }






                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Mar 18 '17 at 16:27









                                                    Florin AndreiFlorin Andrei

                                                    1418




                                                    1418























                                                        2














                                                        You can try the following code,



                                                        $("#dashboard-scroll").scroll(function(){
                                                        var ele = document.getElementById('dashboard-scroll');
                                                        if(ele.scrollHeight - ele.scrollTop === ele.clientHeight){
                                                        console.log('at the bottom of the scroll');
                                                        }
                                                        });





                                                        share|improve this answer




























                                                          2














                                                          You can try the following code,



                                                          $("#dashboard-scroll").scroll(function(){
                                                          var ele = document.getElementById('dashboard-scroll');
                                                          if(ele.scrollHeight - ele.scrollTop === ele.clientHeight){
                                                          console.log('at the bottom of the scroll');
                                                          }
                                                          });





                                                          share|improve this answer


























                                                            2












                                                            2








                                                            2







                                                            You can try the following code,



                                                            $("#dashboard-scroll").scroll(function(){
                                                            var ele = document.getElementById('dashboard-scroll');
                                                            if(ele.scrollHeight - ele.scrollTop === ele.clientHeight){
                                                            console.log('at the bottom of the scroll');
                                                            }
                                                            });





                                                            share|improve this answer













                                                            You can try the following code,



                                                            $("#dashboard-scroll").scroll(function(){
                                                            var ele = document.getElementById('dashboard-scroll');
                                                            if(ele.scrollHeight - ele.scrollTop === ele.clientHeight){
                                                            console.log('at the bottom of the scroll');
                                                            }
                                                            });






                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Jul 6 '18 at 5:06









                                                            Shahrukh AnwarShahrukh Anwar

                                                            907711




                                                            907711























                                                                2














                                                                Try this for match condition if scroll to bottom end



                                                                if ($(this)[0].scrollHeight - $(this).scrollTop() == 
                                                                $(this).outerHeight()) {

                                                                //code for your custom logic

                                                                }





                                                                share|improve this answer






























                                                                  2














                                                                  Try this for match condition if scroll to bottom end



                                                                  if ($(this)[0].scrollHeight - $(this).scrollTop() == 
                                                                  $(this).outerHeight()) {

                                                                  //code for your custom logic

                                                                  }





                                                                  share|improve this answer




























                                                                    2












                                                                    2








                                                                    2







                                                                    Try this for match condition if scroll to bottom end



                                                                    if ($(this)[0].scrollHeight - $(this).scrollTop() == 
                                                                    $(this).outerHeight()) {

                                                                    //code for your custom logic

                                                                    }





                                                                    share|improve this answer















                                                                    Try this for match condition if scroll to bottom end



                                                                    if ($(this)[0].scrollHeight - $(this).scrollTop() == 
                                                                    $(this).outerHeight()) {

                                                                    //code for your custom logic

                                                                    }






                                                                    share|improve this answer














                                                                    share|improve this answer



                                                                    share|improve this answer








                                                                    edited Nov 1 '18 at 14:35









                                                                    Jake Freeman

                                                                    1,6481415




                                                                    1,6481415










                                                                    answered Nov 1 '18 at 13:24









                                                                    Hiren PatelHiren Patel

                                                                    513




                                                                    513























                                                                        1














                                                                        Let me show approch without JQuery. Simple JS function:



                                                                        function isVisible(elem) {
                                                                        var coords = elem.getBoundingClientRect();
                                                                        var topVisible = coords.top > 0 && coords.top < 0;
                                                                        var bottomVisible = coords.bottom < shift && coords.bottom > 0;
                                                                        return topVisible || bottomVisible;
                                                                        }


                                                                        Short example how to use it:



                                                                        var img = document.getElementById("pic1");
                                                                        if (isVisible(img)) { img.style.opacity = "1.00"; }





                                                                        share|improve this answer





















                                                                        • 3





                                                                          This doesn't answer the question. The question was how to detect that the users has scrolled the window all the way to the bottom. Your code is checking if a particular element is in view.

                                                                          – Peter Hall
                                                                          Jan 5 '16 at 18:58
















                                                                        1














                                                                        Let me show approch without JQuery. Simple JS function:



                                                                        function isVisible(elem) {
                                                                        var coords = elem.getBoundingClientRect();
                                                                        var topVisible = coords.top > 0 && coords.top < 0;
                                                                        var bottomVisible = coords.bottom < shift && coords.bottom > 0;
                                                                        return topVisible || bottomVisible;
                                                                        }


                                                                        Short example how to use it:



                                                                        var img = document.getElementById("pic1");
                                                                        if (isVisible(img)) { img.style.opacity = "1.00"; }





                                                                        share|improve this answer





















                                                                        • 3





                                                                          This doesn't answer the question. The question was how to detect that the users has scrolled the window all the way to the bottom. Your code is checking if a particular element is in view.

                                                                          – Peter Hall
                                                                          Jan 5 '16 at 18:58














                                                                        1












                                                                        1








                                                                        1







                                                                        Let me show approch without JQuery. Simple JS function:



                                                                        function isVisible(elem) {
                                                                        var coords = elem.getBoundingClientRect();
                                                                        var topVisible = coords.top > 0 && coords.top < 0;
                                                                        var bottomVisible = coords.bottom < shift && coords.bottom > 0;
                                                                        return topVisible || bottomVisible;
                                                                        }


                                                                        Short example how to use it:



                                                                        var img = document.getElementById("pic1");
                                                                        if (isVisible(img)) { img.style.opacity = "1.00"; }





                                                                        share|improve this answer















                                                                        Let me show approch without JQuery. Simple JS function:



                                                                        function isVisible(elem) {
                                                                        var coords = elem.getBoundingClientRect();
                                                                        var topVisible = coords.top > 0 && coords.top < 0;
                                                                        var bottomVisible = coords.bottom < shift && coords.bottom > 0;
                                                                        return topVisible || bottomVisible;
                                                                        }


                                                                        Short example how to use it:



                                                                        var img = document.getElementById("pic1");
                                                                        if (isVisible(img)) { img.style.opacity = "1.00"; }






                                                                        share|improve this answer














                                                                        share|improve this answer



                                                                        share|improve this answer








                                                                        edited Oct 24 '15 at 15:08

























                                                                        answered Oct 13 '15 at 12:06









                                                                        Alexei ZababurinAlexei Zababurin

                                                                        248410




                                                                        248410








                                                                        • 3





                                                                          This doesn't answer the question. The question was how to detect that the users has scrolled the window all the way to the bottom. Your code is checking if a particular element is in view.

                                                                          – Peter Hall
                                                                          Jan 5 '16 at 18:58














                                                                        • 3





                                                                          This doesn't answer the question. The question was how to detect that the users has scrolled the window all the way to the bottom. Your code is checking if a particular element is in view.

                                                                          – Peter Hall
                                                                          Jan 5 '16 at 18:58








                                                                        3




                                                                        3





                                                                        This doesn't answer the question. The question was how to detect that the users has scrolled the window all the way to the bottom. Your code is checking if a particular element is in view.

                                                                        – Peter Hall
                                                                        Jan 5 '16 at 18:58





                                                                        This doesn't answer the question. The question was how to detect that the users has scrolled the window all the way to the bottom. Your code is checking if a particular element is in view.

                                                                        – Peter Hall
                                                                        Jan 5 '16 at 18:58











                                                                        1














                                                                        All these solutions doesn't work for me on Firefox and Chrome, so I use custom functions from Miles O'Keefe and meder omuraliev like this:



                                                                        function getDocHeight()
                                                                        {
                                                                        var D = document;
                                                                        return Math.max(
                                                                        D.body.scrollHeight, D.documentElement.scrollHeight,
                                                                        D.body.offsetHeight, D.documentElement.offsetHeight,
                                                                        D.body.clientHeight, D.documentElement.clientHeight
                                                                        );
                                                                        }

                                                                        function getWindowSize()
                                                                        {
                                                                        var myWidth = 0, myHeight = 0;
                                                                        if( typeof( window.innerWidth ) == 'number' ) {
                                                                        //Non-IE
                                                                        myWidth = window.innerWidth;
                                                                        myHeight = window.innerHeight;
                                                                        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
                                                                        //IE 6+ in 'standards compliant mode'
                                                                        myWidth = document.documentElement.clientWidth;
                                                                        myHeight = document.documentElement.clientHeight;
                                                                        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                                                                        //IE 4 compatible
                                                                        myWidth = document.body.clientWidth;
                                                                        myHeight = document.body.clientHeight;
                                                                        }
                                                                        return [myWidth, myHeight];
                                                                        }

                                                                        $(window).scroll(function()
                                                                        {
                                                                        if($(window).scrollTop() + getWindowSize()[1] == getDocHeight())
                                                                        {
                                                                        alert("bottom!");
                                                                        }
                                                                        });





                                                                        share|improve this answer




























                                                                          1














                                                                          All these solutions doesn't work for me on Firefox and Chrome, so I use custom functions from Miles O'Keefe and meder omuraliev like this:



                                                                          function getDocHeight()
                                                                          {
                                                                          var D = document;
                                                                          return Math.max(
                                                                          D.body.scrollHeight, D.documentElement.scrollHeight,
                                                                          D.body.offsetHeight, D.documentElement.offsetHeight,
                                                                          D.body.clientHeight, D.documentElement.clientHeight
                                                                          );
                                                                          }

                                                                          function getWindowSize()
                                                                          {
                                                                          var myWidth = 0, myHeight = 0;
                                                                          if( typeof( window.innerWidth ) == 'number' ) {
                                                                          //Non-IE
                                                                          myWidth = window.innerWidth;
                                                                          myHeight = window.innerHeight;
                                                                          } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
                                                                          //IE 6+ in 'standards compliant mode'
                                                                          myWidth = document.documentElement.clientWidth;
                                                                          myHeight = document.documentElement.clientHeight;
                                                                          } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                                                                          //IE 4 compatible
                                                                          myWidth = document.body.clientWidth;
                                                                          myHeight = document.body.clientHeight;
                                                                          }
                                                                          return [myWidth, myHeight];
                                                                          }

                                                                          $(window).scroll(function()
                                                                          {
                                                                          if($(window).scrollTop() + getWindowSize()[1] == getDocHeight())
                                                                          {
                                                                          alert("bottom!");
                                                                          }
                                                                          });





                                                                          share|improve this answer


























                                                                            1












                                                                            1








                                                                            1







                                                                            All these solutions doesn't work for me on Firefox and Chrome, so I use custom functions from Miles O'Keefe and meder omuraliev like this:



                                                                            function getDocHeight()
                                                                            {
                                                                            var D = document;
                                                                            return Math.max(
                                                                            D.body.scrollHeight, D.documentElement.scrollHeight,
                                                                            D.body.offsetHeight, D.documentElement.offsetHeight,
                                                                            D.body.clientHeight, D.documentElement.clientHeight
                                                                            );
                                                                            }

                                                                            function getWindowSize()
                                                                            {
                                                                            var myWidth = 0, myHeight = 0;
                                                                            if( typeof( window.innerWidth ) == 'number' ) {
                                                                            //Non-IE
                                                                            myWidth = window.innerWidth;
                                                                            myHeight = window.innerHeight;
                                                                            } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
                                                                            //IE 6+ in 'standards compliant mode'
                                                                            myWidth = document.documentElement.clientWidth;
                                                                            myHeight = document.documentElement.clientHeight;
                                                                            } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                                                                            //IE 4 compatible
                                                                            myWidth = document.body.clientWidth;
                                                                            myHeight = document.body.clientHeight;
                                                                            }
                                                                            return [myWidth, myHeight];
                                                                            }

                                                                            $(window).scroll(function()
                                                                            {
                                                                            if($(window).scrollTop() + getWindowSize()[1] == getDocHeight())
                                                                            {
                                                                            alert("bottom!");
                                                                            }
                                                                            });





                                                                            share|improve this answer













                                                                            All these solutions doesn't work for me on Firefox and Chrome, so I use custom functions from Miles O'Keefe and meder omuraliev like this:



                                                                            function getDocHeight()
                                                                            {
                                                                            var D = document;
                                                                            return Math.max(
                                                                            D.body.scrollHeight, D.documentElement.scrollHeight,
                                                                            D.body.offsetHeight, D.documentElement.offsetHeight,
                                                                            D.body.clientHeight, D.documentElement.clientHeight
                                                                            );
                                                                            }

                                                                            function getWindowSize()
                                                                            {
                                                                            var myWidth = 0, myHeight = 0;
                                                                            if( typeof( window.innerWidth ) == 'number' ) {
                                                                            //Non-IE
                                                                            myWidth = window.innerWidth;
                                                                            myHeight = window.innerHeight;
                                                                            } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
                                                                            //IE 6+ in 'standards compliant mode'
                                                                            myWidth = document.documentElement.clientWidth;
                                                                            myHeight = document.documentElement.clientHeight;
                                                                            } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                                                                            //IE 4 compatible
                                                                            myWidth = document.body.clientWidth;
                                                                            myHeight = document.body.clientHeight;
                                                                            }
                                                                            return [myWidth, myHeight];
                                                                            }

                                                                            $(window).scroll(function()
                                                                            {
                                                                            if($(window).scrollTop() + getWindowSize()[1] == getDocHeight())
                                                                            {
                                                                            alert("bottom!");
                                                                            }
                                                                            });






                                                                            share|improve this answer












                                                                            share|improve this answer



                                                                            share|improve this answer










                                                                            answered Jan 29 '18 at 17:39









                                                                            hayjhayj

                                                                            19219




                                                                            19219























                                                                                0














                                                                                I used @ddanone answear and added Ajax call.



                                                                                $('#mydiv').on('scroll', function(){
                                                                                function infiniScroll(this);
                                                                                });

                                                                                function infiniScroll(mydiv){
                                                                                console.log($(mydiv).scrollTop()+' + '+ $(mydiv).height()+' = '+ ($(mydiv).scrollTop() + $(mydiv).height()) +' _ '+ $(mydiv)[0].scrollHeight );

                                                                                if($(mydiv).scrollTop() + $(mydiv).height() == $(mydiv)[0].scrollHeight){
                                                                                console.log('bottom found');
                                                                                if(!$.active){ //if there is no ajax call active ( last ajax call waiting for results ) do again my ajax call
                                                                                myAjaxCall();
                                                                                }
                                                                                }


                                                                                }






                                                                                share|improve this answer




























                                                                                  0














                                                                                  I used @ddanone answear and added Ajax call.



                                                                                  $('#mydiv').on('scroll', function(){
                                                                                  function infiniScroll(this);
                                                                                  });

                                                                                  function infiniScroll(mydiv){
                                                                                  console.log($(mydiv).scrollTop()+' + '+ $(mydiv).height()+' = '+ ($(mydiv).scrollTop() + $(mydiv).height()) +' _ '+ $(mydiv)[0].scrollHeight );

                                                                                  if($(mydiv).scrollTop() + $(mydiv).height() == $(mydiv)[0].scrollHeight){
                                                                                  console.log('bottom found');
                                                                                  if(!$.active){ //if there is no ajax call active ( last ajax call waiting for results ) do again my ajax call
                                                                                  myAjaxCall();
                                                                                  }
                                                                                  }


                                                                                  }






                                                                                  share|improve this answer


























                                                                                    0












                                                                                    0








                                                                                    0







                                                                                    I used @ddanone answear and added Ajax call.



                                                                                    $('#mydiv').on('scroll', function(){
                                                                                    function infiniScroll(this);
                                                                                    });

                                                                                    function infiniScroll(mydiv){
                                                                                    console.log($(mydiv).scrollTop()+' + '+ $(mydiv).height()+' = '+ ($(mydiv).scrollTop() + $(mydiv).height()) +' _ '+ $(mydiv)[0].scrollHeight );

                                                                                    if($(mydiv).scrollTop() + $(mydiv).height() == $(mydiv)[0].scrollHeight){
                                                                                    console.log('bottom found');
                                                                                    if(!$.active){ //if there is no ajax call active ( last ajax call waiting for results ) do again my ajax call
                                                                                    myAjaxCall();
                                                                                    }
                                                                                    }


                                                                                    }






                                                                                    share|improve this answer













                                                                                    I used @ddanone answear and added Ajax call.



                                                                                    $('#mydiv').on('scroll', function(){
                                                                                    function infiniScroll(this);
                                                                                    });

                                                                                    function infiniScroll(mydiv){
                                                                                    console.log($(mydiv).scrollTop()+' + '+ $(mydiv).height()+' = '+ ($(mydiv).scrollTop() + $(mydiv).height()) +' _ '+ $(mydiv)[0].scrollHeight );

                                                                                    if($(mydiv).scrollTop() + $(mydiv).height() == $(mydiv)[0].scrollHeight){
                                                                                    console.log('bottom found');
                                                                                    if(!$.active){ //if there is no ajax call active ( last ajax call waiting for results ) do again my ajax call
                                                                                    myAjaxCall();
                                                                                    }
                                                                                    }


                                                                                    }







                                                                                    share|improve this answer












                                                                                    share|improve this answer



                                                                                    share|improve this answer










                                                                                    answered Jan 19 '16 at 14:43









                                                                                    Henrique C.Henrique C.

                                                                                    761925




                                                                                    761925























                                                                                        0














                                                                                        To stop repeated alert of Nick's answer



                                                                                        ScrollActivate();

                                                                                        function ScrollActivate() {
                                                                                        $(window).on("scroll", function () {
                                                                                        if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                                                                                        $(window).off("scroll");
                                                                                        alert("near bottom!");
                                                                                        }
                                                                                        });
                                                                                        }





                                                                                        share|improve this answer




























                                                                                          0














                                                                                          To stop repeated alert of Nick's answer



                                                                                          ScrollActivate();

                                                                                          function ScrollActivate() {
                                                                                          $(window).on("scroll", function () {
                                                                                          if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                                                                                          $(window).off("scroll");
                                                                                          alert("near bottom!");
                                                                                          }
                                                                                          });
                                                                                          }





                                                                                          share|improve this answer


























                                                                                            0












                                                                                            0








                                                                                            0







                                                                                            To stop repeated alert of Nick's answer



                                                                                            ScrollActivate();

                                                                                            function ScrollActivate() {
                                                                                            $(window).on("scroll", function () {
                                                                                            if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                                                                                            $(window).off("scroll");
                                                                                            alert("near bottom!");
                                                                                            }
                                                                                            });
                                                                                            }





                                                                                            share|improve this answer













                                                                                            To stop repeated alert of Nick's answer



                                                                                            ScrollActivate();

                                                                                            function ScrollActivate() {
                                                                                            $(window).on("scroll", function () {
                                                                                            if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
                                                                                            $(window).off("scroll");
                                                                                            alert("near bottom!");
                                                                                            }
                                                                                            });
                                                                                            }






                                                                                            share|improve this answer












                                                                                            share|improve this answer



                                                                                            share|improve this answer










                                                                                            answered Feb 8 '17 at 7:38









                                                                                            Arun Prasad E SArun Prasad E S

                                                                                            3,62023249




                                                                                            3,62023249























                                                                                                0














                                                                                                My solution in plain js:






                                                                                                let el=document.getElementById('el');
                                                                                                el.addEventListener('scroll', function (e) {
                                                                                                if (el.scrollHeight - el.scrollTop - el.clientHeight<0) {
                                                                                                console.log('Bottom')
                                                                                                }
                                                                                                });

                                                                                                #el{
                                                                                                width:300px;
                                                                                                height:100px;
                                                                                                overflow-y:scroll;
                                                                                                }

                                                                                                <div id="el">
                                                                                                <div>content</div>
                                                                                                <div>content</div>
                                                                                                <div>content</div>
                                                                                                <div>content</div>
                                                                                                <div>content</div>
                                                                                                <div>content</div>
                                                                                                <div>content</div>
                                                                                                <div>content</div>
                                                                                                <div>content</div>
                                                                                                <div>content</div>
                                                                                                <div>content</div>
                                                                                                </div>








                                                                                                share|improve this answer




























                                                                                                  0














                                                                                                  My solution in plain js:






                                                                                                  let el=document.getElementById('el');
                                                                                                  el.addEventListener('scroll', function (e) {
                                                                                                  if (el.scrollHeight - el.scrollTop - el.clientHeight<0) {
                                                                                                  console.log('Bottom')
                                                                                                  }
                                                                                                  });

                                                                                                  #el{
                                                                                                  width:300px;
                                                                                                  height:100px;
                                                                                                  overflow-y:scroll;
                                                                                                  }

                                                                                                  <div id="el">
                                                                                                  <div>content</div>
                                                                                                  <div>content</div>
                                                                                                  <div>content</div>
                                                                                                  <div>content</div>
                                                                                                  <div>content</div>
                                                                                                  <div>content</div>
                                                                                                  <div>content</div>
                                                                                                  <div>content</div>
                                                                                                  <div>content</div>
                                                                                                  <div>content</div>
                                                                                                  <div>content</div>
                                                                                                  </div>








                                                                                                  share|improve this answer


























                                                                                                    0












                                                                                                    0








                                                                                                    0







                                                                                                    My solution in plain js:






                                                                                                    let el=document.getElementById('el');
                                                                                                    el.addEventListener('scroll', function (e) {
                                                                                                    if (el.scrollHeight - el.scrollTop - el.clientHeight<0) {
                                                                                                    console.log('Bottom')
                                                                                                    }
                                                                                                    });

                                                                                                    #el{
                                                                                                    width:300px;
                                                                                                    height:100px;
                                                                                                    overflow-y:scroll;
                                                                                                    }

                                                                                                    <div id="el">
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    </div>








                                                                                                    share|improve this answer













                                                                                                    My solution in plain js:






                                                                                                    let el=document.getElementById('el');
                                                                                                    el.addEventListener('scroll', function (e) {
                                                                                                    if (el.scrollHeight - el.scrollTop - el.clientHeight<0) {
                                                                                                    console.log('Bottom')
                                                                                                    }
                                                                                                    });

                                                                                                    #el{
                                                                                                    width:300px;
                                                                                                    height:100px;
                                                                                                    overflow-y:scroll;
                                                                                                    }

                                                                                                    <div id="el">
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    </div>








                                                                                                    let el=document.getElementById('el');
                                                                                                    el.addEventListener('scroll', function (e) {
                                                                                                    if (el.scrollHeight - el.scrollTop - el.clientHeight<0) {
                                                                                                    console.log('Bottom')
                                                                                                    }
                                                                                                    });

                                                                                                    #el{
                                                                                                    width:300px;
                                                                                                    height:100px;
                                                                                                    overflow-y:scroll;
                                                                                                    }

                                                                                                    <div id="el">
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    </div>





                                                                                                    let el=document.getElementById('el');
                                                                                                    el.addEventListener('scroll', function (e) {
                                                                                                    if (el.scrollHeight - el.scrollTop - el.clientHeight<0) {
                                                                                                    console.log('Bottom')
                                                                                                    }
                                                                                                    });

                                                                                                    #el{
                                                                                                    width:300px;
                                                                                                    height:100px;
                                                                                                    overflow-y:scroll;
                                                                                                    }

                                                                                                    <div id="el">
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    <div>content</div>
                                                                                                    </div>






                                                                                                    share|improve this answer












                                                                                                    share|improve this answer



                                                                                                    share|improve this answer










                                                                                                    answered Oct 22 '18 at 14:57









                                                                                                    Bakos BenceBakos Bence

                                                                                                    2514




                                                                                                    2514























                                                                                                        0














                                                                                                        Here's my two cents as the accepted answer didn't work for me.



                                                                                                        var documentAtBottom = (document.documentElement.scrollTop + window.innerHeight) >= document.documentElement.scrollHeight;





                                                                                                        share|improve this answer






























                                                                                                          0














                                                                                                          Here's my two cents as the accepted answer didn't work for me.



                                                                                                          var documentAtBottom = (document.documentElement.scrollTop + window.innerHeight) >= document.documentElement.scrollHeight;





                                                                                                          share|improve this answer




























                                                                                                            0












                                                                                                            0








                                                                                                            0







                                                                                                            Here's my two cents as the accepted answer didn't work for me.



                                                                                                            var documentAtBottom = (document.documentElement.scrollTop + window.innerHeight) >= document.documentElement.scrollHeight;





                                                                                                            share|improve this answer















                                                                                                            Here's my two cents as the accepted answer didn't work for me.



                                                                                                            var documentAtBottom = (document.documentElement.scrollTop + window.innerHeight) >= document.documentElement.scrollHeight;






                                                                                                            share|improve this answer














                                                                                                            share|improve this answer



                                                                                                            share|improve this answer








                                                                                                            edited Dec 18 '18 at 11:16









                                                                                                            alseether

                                                                                                            1,48711529




                                                                                                            1,48711529










                                                                                                            answered Nov 22 '18 at 1:53









                                                                                                            Vince PanuccioVince Panuccio

                                                                                                            8,7171981132




                                                                                                            8,7171981132

















                                                                                                                protected by animuson Sep 24 '13 at 20:41



                                                                                                                Thank you for your interest in this question.
                                                                                                                Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                                                                                Would you like to answer one of these unanswered questions instead?



                                                                                                                Popular posts from this blog

                                                                                                                Create new schema in PostgreSQL using DBeaver

                                                                                                                Deepest pit of an array with Javascript: test on Codility

                                                                                                                Costa Masnaga