检测 Scroll 何时到达页面底部 [不使用 jQuery] [英] Detect when Scroll reaches the BOTTOM of the page [ without jQuery ]

查看:20
本文介绍了检测 Scroll 何时到达页面底部 [不使用 jQuery]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在滚动到达页面底部时发出警报,如下所示:

I want to alert something when the scroll reaches the BOTTOM of the page, like this:

$(function(){
  $(document).scroll(function() {
    if($(document).scrollTop() == 0) alert("top");
  })
})

但没有 jQuery,并在到达底部时发出警报.

But without jQuery, and alert when reaches the Bottom.

推荐答案

document.addEventListener('scroll', function (event) {
    if (document.body.scrollHeight == 
        document.body.scrollTop +        
        window.innerHeight) {
        alert("Bottom!");
    }
});

JSFiddle 在这里:http://jsfiddle.net/cSer6/

JSFiddle here: http://jsfiddle.net/cSer6/

这篇关于检测 Scroll 何时到达页面底部 [不使用 jQuery]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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