I'm trying to write a function in jQuery that could create an infinite scroll with divs that are already in my page. I would like to make them appear and load randomly when you reached the end of the original content. The thing is that I'm just starting to use jQuery and I don't really know who to do it!
All my divs have a class of item
and are inside a .content
div. For the moment I have 11 of them.
I tried to .append(specific div)
and it worked, but I don't know how to do it with a list of div.
Does anyone have an idea of what I should do?
$(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')
});
});
}
});