【问题标题】:Horizontal AJAX posts loader, detect when scrollbar reaches the end水平 AJAX 帖子加载器,检测滚动条何时到达末尾
【发布时间】:2014-08-18 09:58:59
【问题描述】:

我已经使用overflow-x:scroll 设置了一个div (#reviewspostscont),现在我想使用AJAX 加载帖子,但我无法检测到滚动条何时到达最右端。 下面是我到目前为止的代码,我不明白它有什么问题。 提前致谢, 马特

   $('#reviewspostscont').scroll(function(){
   var $this = $(this);
   scrollPercentage = 100 * $(this).scrollLeft() / ($('#reviewspostscont').width() - $(this).width());

                if  (scrollPercentage == 100){
                    alert('end!');  // just to test the code, then AJAX
                }
        }); 

【问题讨论】:

    标签: javascript jquery ajax scroll infinite-scroll


    【解决方案1】:

    问题在于如何计算总滚动宽度。我添加了一个JSFiddle。基本上,而不是:

    scrollPercentage = 100 * $(this).scrollLeft() / 
        ($('#reviewspostscont').width() - $(this).width());
    

    你应该有:

    scrollPercentage = 100 * $(this).scrollLeft() /
        ($(this)[0].scrollWidth - $(this).width());
    

    【讨论】:

    • 我在更改代码时忘记了它,非常感谢!
    猜你喜欢
    • 2019-04-18
    • 1970-01-01
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    相关资源
    最近更新 更多