【发布时间】:2014-10-20 10:23:21
【问题描述】:
我在新闻索引页面中有许多 article div,其中每个 div 都包含一个新闻预告片。
我想显示前 10 个,然后在向下滚动并到达底部时,我将显示另外 10 个等。这是我的 js。
$(function () {
shown = 0;
$('.artikel').hide();
$('.artikel').each(function () {
if (shown <= 10) {
shown += 1;
$(this).show();
}
});
$(window).scroll(function () {
if ($(window).scrollTop() + $(window).height() == $(document).height()) {
setTimeout(function () {
// problem here.
$('.artikel').each(function () {
if (shown <= 20) {
shown += 1;
$(this).show();
}
});
}, 1500);
}
});
});
我的逻辑问题是,一旦我滚动到底部,setTimeOut 中的函数将从头开始再次计算所有articles。
我希望它显示从最后显示的文章开始的下 10 条新闻。有人可以帮忙吗?
【问题讨论】:
-
在你的 if 语句之后添加
shown += 10,它应该在每次刷新时添加 10。
标签: javascript jquery html