如何使用JQuery来检测用户是否滚动到页面底部

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

本文关键字:滚动 底部 是否 用户 何使用 JQuery 检测      更新时间:2023-09-26

一旦触底,是否有回调函数?

您可以在窗口上以这种方式使用.scroll()事件:

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

查看实时演示

要检测用户是否在页面下方3/4,你可以尝试这个

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() > $(document).height() - .75*$(document).height()) {
       alert("3/4th of bottom!");
   }
});