【发布时间】:2019-10-15 06:43:58
【问题描述】:
我正在尝试在 jQuery 中编写一个函数,该函数可以使用我页面中已有的 div 创建一个无限滚动。当您到达原始内容的末尾时,我想让它们随机出现并加载。问题是我刚刚开始使用 jQuery,我真的不知道该由谁来做!
我所有的 div 都有一个 item 类,并且在 .content div 中。目前我有 11 个。
我尝试.append(specific div) 并且它有效,但我不知道如何使用 div 列表来做到这一点。
有人知道我应该怎么做吗?
$(document).ready(function() {
var collection = $("div.content .item").get();
collection.sort(function() {
return Math.random() * 10 > 5 ? 1 : -1;
});
$.each(collection, function(i, el) {
$(el).appendTo($(el).parent());
});
});
$(window).scroll(function() {
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
$(".content").append('Here is where I dont know what I should write')
});
});
}
});
【问题讨论】:
标签: javascript jquery html infinite-scroll