简体   繁体   中英

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

一旦它触及底部,那么有一个回调函数?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM