Skip to content

Instantly share code, notes, and snippets.

@knorthfield
Created May 10, 2012 14:56
Show Gist options
  • Save knorthfield/2653687 to your computer and use it in GitHub Desktop.
Save knorthfield/2653687 to your computer and use it in GitHub Desktop.
jQuery detect if scrolled to bottom or near it
$(window).scroll(function(){
toScroll = $(document).height() - $(window).height() - 250;
if ( $(this).scrollTop() > toScroll ) {
// Do something
}
});
@clain4u
Copy link

clain4u commented Jan 9, 2019

Indeed a good idea to trigger even few pixels before reaching the page bottom, helpful while implementing pagination, better user experience.

@pavithra-r
Copy link

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');
    }
});

Working as expected.Thank u so much

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