滚动到页面末尾时使用Jquery发出警报 [英] Alert using Jquery when Scroll to end of Page

查看:84
本文介绍了滚动到页面末尾时使用Jquery发出警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以使用Jquery找出页面结尾,因此可以显示一条简单消息,表明您已到达页面结尾.

Is there a way to find out page end using Jquery, so that a simple message can be displayed saying you have reached end of the page.

推荐答案

How to tell when you're at the bottom of a page:

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

当然,您希望在用户滚动时触发以上内容:

Of course you want to fire the above whenever the user scrolls:

$(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.");
    }
});

这是一个jsFiddle示例 用户滚动到页面底部时,完成!滚动到页面顶部"链接.

Here is a jsFiddle example that fades in a "You're Done! Scroll to Top of Page" link when the user has scrolled to the bottom of the page.

参考:

  • .scroll()
  • .scrollTop()
  • offsetHeight
  • clientHeight

这篇关于滚动到页面末尾时使用Jquery发出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆