滚动到页面末尾时使用Jquery进行警报

San*_*rst 9 jquery browser-scrollbars

有没有办法使用Jquery找出页面结束,这样就可以显示一条简单的消息,说明你已到达页面的末尾.

Pet*_*tai 18

如何判断您何时位于页面底部:

if (  document.documentElement.clientHeight + 
      $(document).scrollTop() >= document.body.offsetHeight )
{ 
    // Display alert or whatever you want to do when you're 
    //   at the bottom of the page. 
    alert("You're at the bottom of the page.");
}
Run Code Online (Sandbox Code Playgroud)

当然,只要用户滚动,你就想触发上面的内容:

$(window).scroll(function() {
    if (  document.documentElement.clientHeight + 
          $(document).scrollTop() >= document.body.offsetHeight )
    { 
        // Display alert or whatever you want to do when you're 
        //   at the bottom of the page. 
        alert("You're at the bottom of the page.");
    }
});
Run Code Online (Sandbox Code Playgroud)

这是一个jsFiddle示例,当用户滚动到页面底部时,它会淡入"您已完成!滚动到页面顶部"链接.

参考文献:


Mat*_*ela 6

这将工作,我在IE 7,8,9,FF 3.6,Chrome 6和Opera 10.6中进行了测试

$(window).scroll(function()
{
    if (document.body.scrollHeight - $(this).scrollTop()  <= $(this).height())
    {
        alert('end');
    }
});
Run Code Online (Sandbox Code Playgroud)