gpt4 book ai didi

javascript - 检测 Scroll 何时到达页面的底部 [没有 jQuery]

转载 作者:可可西里 更新时间:2023-11-01 01:35:40 25 4
gpt4 key购买 nike

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

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

但没有 jQuery,到达底部时发出警报。

最佳答案

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

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

关于javascript - 检测 Scroll 何时到达页面的底部 [没有 jQuery],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10059888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com