Search code examples
jquerybrowser-scrollbars

Alert using Jquery when Scroll to end of Page


Is there a way to find out page end using Jquery, so that a simple message can be displayed saying you have reached end of the page.


Solution

  • How to tell when you're at the bottom of a page:

    if (  document.documentElement.clientHeight + 
          $(document).scrollTop() >= document.body.offsetHeight )
    { 
        // Display alert or whatever you want to do when you're 
        //   at the bottom of the page. 
        alert("You're at the bottom of the page.");
    }
    

    Of course you want to fire the above whenever the user scrolls:

    $(window).scroll(function() {
        if (  document.documentElement.clientHeight + 
              $(document).scrollTop() >= document.body.offsetHeight )
        { 
            // Display alert or whatever you want to do when you're 
            //   at the bottom of the page. 
            alert("You're at the bottom of the page.");
        }
    });
    

    Here is a jsFiddle example that fades in a "You're Done! Scroll to Top of Page" link when the user has scrolled to the bottom of the page.

    References: