jQuery:检测滚动的底部不起作用,仅检测顶部 [英] jQuery: detecting reaching bottom of scroll doesn't work, only detects the top

查看:130
本文介绍了jQuery:检测滚动的底部不起作用,仅检测顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我的问题是一个看似简单的问题.

So basically my problem is a seemingly simple one.

您可以在 http://furnace.howcode.com 上看到它的运行情况(请注意,数据是通过Ajax返回的,因此,如果没有任何反应,请稍等一下!).

You can see it in action at http://furnace.howcode.com (please note that data is returned via Ajax, so if nothing happens give it a few moments!).

发生什么意思是,当您到达滚动的底部时,在第二列中,将返回下5个结果.

What's MEANT to happen, is in the second column when you reach the bottom of scrolling, the next 5 results are returned.

但是实际上发生的是,当您按滚动区域的TOP时,它仅返回5个结果.尝试一下:向下滚动,什么都不会发生.向上滚动回到顶部,返回结果.

But what actually happens is it only returns the 5 results when you hit the TOP of the scroll area. Try it: scroll down, nothing happens. Scroll back up to the top, the results are returned.

怎么了?

这是我正在使用的代码:

Here's my code I'm using:

$('#col2').scroll(function(){
    if ($('#col2').scrollTop() == $('#col2').height() - $('#col2').height()){
       loadMore();
    }
});

loadMore();是获取数据并将其附加的函数.

loadMore(); is the function that gets the data and appends it.

那么这里出了什么问题?感谢您的帮助!

So what's going wrong here? Thanks for your help!

推荐答案

您的数学是错误的,您的说法是,如果滚动条位置等于列的高度减去列的高度(等于零),则加载更多.这就是为什么loadMore()在列顶部被调用的原因.

Your math is wrong, your saying if the scrollbar position is equal to the height of the column minus the height of the column (which equals zero) load more. that's why your loadMore() is called at the top of your col.

尝试:

$('#col2').scroll(function(){
    if ($('#col2').scrollTop() == $('#col2').height()){
       loadMore();
    }
});

这篇关于jQuery:检测滚动的底部不起作用,仅检测顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆