infinite-scroll
我通过向回调添加一个计数器来解决问题,如下所示:
var total = $j(".pagination a:last").html();
var pgCount = 1;
var numPg = total;
// jQuery InfiniteScroll Plugin.
container.infinitescroll({
navSelector : '.pagination',
nextSelector : '.pagination a:first',
itemSelector : '.journal-entry-wrapper',
animate: true,
loading: {
finishedMsg: 'No more content to load.',
img: 'http://i.imgur.com/6RMhx.gif'
}
},
// Trigger Masonry as a callback.
function( newElements ) {
pgCount++;
if(pgCount == numPg) {
$j(window).unbind('.infscr');
container.masonry('reload');
container.append( newElements ).masonry( 'appended', newElements, true );
$j('#infscr-loading').find('em').text('No more content to load.');
$j('#infscr-loading').animate({
opacity: 1
}, 200);
setTimeout(function() {
$j('#infscr-loading').animate({
opacity: 0
}, 300);
});
} else {
loadPosts(newElements);
}
});
});
function loadPosts(newElements) {
// Hide new posts while they are still loading.
var newElems = $j( newElements ).css({ opacity: 0 });
// Ensure that images load before adding to masonry layout.
newElems.imagesLoaded(function() {
// Show new elements now that they're loaded.
newElems.animate({ opacity: 1 });
container.masonry( 'appended', newElems, true );
// Animate opaque post covers on hover.
$j(newElems).hover(function() {
$j(this).find('.postCover').stop(true, true).fadeOut(200);
}, function() {
$j(this).find('.postCover').stop(true, true).fadeIn(200);
});
});
}