当用户滚动“近"时,加载更多内容.页面底部? [英] Load more content when user scrolls "near" bottom of page?
本文介绍了当用户滚动“近"时,加载更多内容.页面底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用它来检测滚动到页面底部.但是如何检测距页面底部的距离?
I use this to detect scroll to the bottom of page. But how do I detect a distance from the bottom of the page?
if($(window).scrollTop() + $(window).height() == $(document).height() ) {
.. my ajax here
}
我的意思是我希望函数在他离页面底部100px或200px而不是页面底部时执行.我该如何更改?
I mean i want the function to execute when he is 100px or 200px from the bottom, and not in the very bottom of page. How would I change this?
还:是否可以捕获滚动条是否位于显示加载内容的特定元素(例如我的大容器)的末尾.
Also: is it possible, to instead catch if the scroll is at the last of a specific element (say my big CONTAINER) which shows the loaded content.
预先感谢
推荐答案
var nearToBottom = 100;
if ($(window).scrollTop() + $(window).height() >
$(document).height() - nearToBottom) {
.. my ajax here
}
或滚动到.CONTAINER的底部
or to scroll to the bottom of .CONTAINER
if ($(window).scrollTop() + $(window).height() >=
$('.CONTAINER').offset().top + $('.CONTAINER').height() ) {
.. my ajax here
}
这篇关于当用户滚动“近"时,加载更多内容.页面底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文