Random infinite scroll and doesnt repeat already published divs
Hi,
I have infinite scroll with JQuery. But repeats already published divs when scrolling down. I want that randomly (from about 7 different div content pages with each page having an x number of div content, those div contents are news articles), a random number of artcles are taken from each page and published on my home page. And that this process repeats itself till all artcles, over all 7 pages, have been published. So, no repeats happen on my home page. I am breaking my head over this one. This is my code so far. Hope somebodys can help? Thank you. Sorry for my poor English.
jQuery(document).ready(function() {
//location.href = 'index.html#start';
var pages = new Array();
var current = 0;
var loaded = new Array();
$('#pages a').each(function(index) {
pages[index] = $(this).attr('href');
loaded[$(this).attr('href')] = 0;
});
$(window).scroll(function(e){
if($(window).scrollTop() + $(window).height() >= $(document).height() - 300) {
console.log("bottom of the page reached!");
loaded[pages[current+1]] = loaded[pages[current+1]] + 1;
if(loaded[pages[current+1]] <= 1)
loadMoreContent(current+1);
}
});
function loadMoreContent(position) {
if(position < pages.length) {
$('#loader').fadeIn('slow', function() {
$.get(pages[position], function(data) {
$('#loader').fadeOut('slow', function() {
$('#scroll-container').append(data).fadeIn(999);
current=position;
});
});
});
}
}
});