【问题标题】:Load more content when user scrolls "near" bottom of page?当用户滚动页面“接近”底部时加载更多内容?
【发布时间】:2012-10-24 21:18:37
【问题描述】:

我用它来检测滚动到页面底部。但是如何检测到页面底部的距离?

if($(window).scrollTop() + $(window).height() == $(document).height() ) {
 .. my ajax here
}

我的意思是我希望函数在他离底部 100 像素或 200 像素时执行,而不是在页面的最底部。我该如何改变呢?

另外:如果滚动是在显示加载内容的特定元素(比如我的大容器)的最后一个,是否可以捕获。

提前致谢

【问题讨论】:

标签: jquery


【解决方案1】:
var nearToBottom = 100;

if ($(window).scrollTop() + $(window).height() > 
    $(document).height() - nearToBottom) { 
 .. my ajax here 
} 

或滚动到 .CONTAINER 的底部

if ($(window).scrollTop() + $(window).height() >= 
    $('.CONTAINER').offset().top + $('.CONTAINER').height() ) { 
 .. my ajax here 
} 

【讨论】:

    【解决方案2】:

    这会对你有所帮助。

    <script>
     $(window).scroll(function () {
        if ($(document).height() <= $(window).scrollTop() + $(window).height()) {
            alert("End Of The Page");
        }
     });
    </script>
    

    通过此链接查看整篇文章并详细说明其工作原理。

    load more content when browser scroll to end of page in jquery

    【讨论】:

      猜你喜欢
      • 2015-03-03
      • 2017-01-01
      • 2019-01-23
      • 1970-01-01
      • 2012-05-17
      • 2015-08-23
      • 1970-01-01
      • 2012-10-25
      • 2018-05-22
      相关资源
      最近更新 更多