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

查看:19
本文介绍了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.

但实际发生的是,当您点击滚动区域的顶部时,它只返回 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天全站免登陆