我正在尝试使用Infinite Scroll设置Masonry,但它可以正常加载所有项目,然后当我点击下一页链接时,它会再次加载它们。
导航:
<div class="more" id="navigation">
<a href="./?page=2">MORE IDEAS</a>
</div>
JS:
$(document).ready( function() {
(function() {
// Main content container
var $container = $('.grid');
// Masonry + ImagesLoaded
$container.imagesLoaded(function(){
$container.masonry({
itemSelector: '.grid-item',
columnWidth: '.grid-sizer',
gutter: '.gutter-sizer',
percentPosition: true
});
});
// Infinite Scroll
$container.infinitescroll({
// selector for the paged navigation (it will be hidden)
navSelector : "#navigation",
// selector for the NEXT link (to page 2)
nextSelector : "#navigation a",
// selector for all items you'll retrieve
itemSelector : ".grid-item",
},
// Trigger Masonry as a callback
function( newElements ) {
// hide new items while they are loading
var $newElems = $( newElements ).css({ opacity: 0 });
// ensure that images load before adding to masonry layout
$newElems.imagesLoaded(function(){
// show elems now they're ready
$newElems.animate({ opacity: 1 });
$container.masonry( 'appended', $newElems, true );
});
});
// Pause Infinite Scroll
$(window).unbind('.infscr');
// Resume Infinite Scroll
$('.more a').click(function(){
$container.infinitescroll('retrieve');
return false;
});
})();
});
内容:
<div class="grid">
<div class="grid-sizer"></div>
<div class="gutter-sizer"></div>
<div class="grid-item">Item 1</div>
<div class="grid-item">Item 2</div>
<div class="grid-item">Item 3</div>
<div class="grid-item">Item 4</div>
<div class="grid-item">Item 5</div>
<div class="grid-item">Item 6</div>
</div>
目前它加载所有项目,1到6,然后当我单击“加载更多”按钮时,它再次加载项目1到6。我看了几个与此类似的问题,但它们是不同的情况。它可能很简单,任何帮助都会非常受欢迎。
答案 0 :(得分:0)
想出来。
您需要将您想要加载的部分内容放在第二位,并将其放在另一个html页面中。然后,您需要设置导航链接以转到该页面。因为它只是设置为?page = 2,它只是再次加载相同的页面。