How do I use JQuery to detect if a user scrolls to

2019-02-10 07:59发布

问题:

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

回答1:

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!");
   }
});