javascript 如何使用 JQuery 检测用户是否滚动到页面底部?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9697748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:30:31 来源:igfitidea点击:
How do I use JQuery to detect if a user scrolls to the bottom of the page?
提问by TIMEX
And once it hits the bottom,then have a callback function?
一旦它触底,然后有一个回调函数?
回答by Java
You can use .scroll() event in this way on your window:
您可以在窗口上以这种方式使用 .scroll() 事件:
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});
check live demo
检查现场演示
to detect if the user is 3/4 down the page you can try this one
要检测用户是否位于页面下方的 3/4,您可以试试这个
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - .75*$(document).height()) {
alert("3/4th of bottom!");
}
});