Skip to content

Instantly share code, notes, and snippets.

@toshimaru
Last active March 25, 2026 00:25
Show Gist options
  • Select an option

  • Save toshimaru/6102647 to your computer and use it in GitHub Desktop.

Select an option

Save toshimaru/6102647 to your computer and use it in GitHub Desktop.
Detect the scrolling to bottom of the page using jQuery.
$(window).on("scroll", function() {
var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
// when scroll to bottom of the page
}
});
@zaqihsn
Copy link
Copy Markdown

zaqihsn commented Dec 18, 2020

find out particular elements scroll bottom
$(".user_container").scroll(function(e){
console.log()
var scrollHeight = $(this).find("table").height(); //user_container inside elements height
var currentElementHeight = $(this).height()
var scrollMax = scrollHeight - currentElementHeight;
if(scrollMax == $(this).scrollTop()){
console.log("reached at Bottom");
}
})

Copy link
Copy Markdown

ghost commented Dec 5, 2021

@areghunanyan thanks

$(window).scroll(function() {  
    var scrollHeight = window.scrollY || $(window).scrollTop();                                          
        if ((window.innerHeight + scrollHeight) >= document.body.offsetHeight) {                       
            // do something                                                    
        }                                                                                                                
}); 

I fixed little bit to work on ie too. this works fine for me.

@GabrielHilgert
Copy link
Copy Markdown

GabrielHilgert commented Dec 27, 2021

If you want to do it in a element scroll, you can do this:

// ...
        var parent = $('#parent')
        var child = $('#child')
parent.on("scroll", function() {
	if (parent.scrollTop()+parent[0].offsetHeight-child[0].scrollHeight === 0) {
	    // when scroll to bottom of the page
	}
});

@Man0j-M
Copy link
Copy Markdown

Man0j-M commented Mar 10, 2022

Awesome, thanks. This should be the first result for anyone who is searching for 'detect scroll to botton of page using jquery'.

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