I have this code:
$(document).ready(function() {
var number = 10;
var offset = 10;
var page_number = 2;
$(window).bind('scroll', function(e) {
if($(window).scrollTop() + $(window).height() >
$(document).height() - 10) {
$('.loading-more').html('Keep scrolling for more posts to load..');
$.post('<?php bloginfo('siteurl') ?>/wp-admin/admin-ajax.php', {
action: 'and_action',
off: offset+number,
pagenumber: page_number - 1
}, function(data) {
offset = offset+number;
$('.empty-div').append('<p><strong>Page '+page_number+'</strong></p><br />'+data);
page_number += 1;
$(this).unbind(e);
});
}
});
});
This checks to see if the user is at the bottom of the page and is loading more content. The problem is that the user scrolls slowly around the critical point or quickly and quickly scrolls up and down, the function $.postruns several times, which means that you get several instances of the data that I load.
What I tried to do was a required and untied variable e, but it did not work so well. In any case, you can run the function postonce, and then have the reset function, so when the user scrolls again, it starts again, so more than one instance of the data is not loaded?