[英]Jquery ajax infinite scroll exclude footer height
I'm working on ajax infinite scroll. 我正在研究ajax无限滚动。 I have below code to make ajax request after scrolling at end,
我有下面的代码来滚动结束后发出ajax请求,
$(window).scroll(function(){
if($(window).scrollTop() >= ($(document).height() - $(window).height())){
loadlist();
}
});
But it fires when scrolled at end (including footer.). 但是,当最终滚动时(包括页脚),它将触发。 But I want it fired when the footer is just starting to show while scrolling (footer height is 300px).
但是我希望在滚动时页脚才开始显示时触发(页脚高度为300px)。
I researched and tried following code, 我研究并尝试了以下代码,
$(window).scroll(function(){
if($(window).scrollTop() >= ($(document).height() - $(window).height()) - 300){ // 300px footer height
loadlist();
}
});
But It seems dirty. 但这似乎很脏。 the function gets fired too many times when scrolling.
滚动时,该函数被触发太多次。 any good solutions ?
有什么好的解决方案吗?
I'd take the approach of triggering the behaviour when your footer element first scrolls into view. 当您的页脚元素首次滚动到视图中时,我将采取触发行为的方法。
var $footer = $("#my-footer");
$(window).scroll( function() {
if (isScrolledIntoView($footer) ) loadList();
});
See Check if element is visible after scrolling to get the code for isScrolledIntoView()
. 请参阅滚动后检查元素是否可见以获取
isScrolledIntoView()
的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.