Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use JQuery to detect if a user scrolls to the bottom of the page?

And once it hits the bottom,then have a callback function?

like image 665
TIMEX Avatar asked Mar 14 '12 07:03

TIMEX


1 Answers

You can use .scroll() event in this way on your window:

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

check live demo

to detect if the user is 3/4 down the page you can try this one

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() > $(document).height() - .75*$(document).height()) {
       alert("3/4th of bottom!");
   }
});
like image 133
Java Avatar answered Oct 19 '22 21:10

Java