[英]How can I iterate this function to make the ajax call every time the user hits the bottom of the page?
I am trying to implement the following for infinite scroll on my page. 我正在尝试为页面上的无限滚动实现以下内容。
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $(document).height() - 350) {
//ajax call happens here
}
All goes well when the user reaches the bottom of the page for the first time. 当用户第一次到达页面底部时,一切都会顺利进行。 The ajax call happens and more data is loaded onto the page. 发生ajax调用,并且更多数据被加载到页面上。 However, the ajax call does not happen when the user reaches the bottom of the page again. 但是,当用户再次到达页面底部时,ajax调用不会发生。 So my question is, does this function iterate every time the user reaches the bottom of the page or does it happen only once? 所以我的问题是,此功能是在用户每次到达页面底部时重复执行还是仅发生一次? If so, what should I add to make the ajax call every time the user reaches the bottom of the page? 如果是这样,每当用户到达页面底部时,我应该添加什么来进行ajax调用? I appreciate your input. 感谢您的投入。
This has been answered here: 这已经在这里得到回答:
https://stackoverflow.com/a/3898152/6265633 https://stackoverflow.com/a/3898152/6265633
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("bottom!");
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.