Reputation: 3073
Here is my sample code:
$(window).scroll(function () {
if ($(window).scrollTop() >= $(document).height() - $(window).height()) {
// Run code here...
}
});
I use the above code to execute stuff when user scroll to bottom of page. Instead, how can I make the code executed when user scroll to bottom of specific element (e.g. #content) and not the whole document.
Thank you.
Upvotes: 3
Views: 1361
Reputation: 5475
This should probably work.
$(window).scroll(function () {
if ($(window).scrollTop() >= $(elem).position().top + $(elem).height() /* add padding if needed. */) {
// Run code here...
}
});
Upvotes: 5