【发布时间】:2014-06-10 11:33:26
【问题描述】:
我在砌体方面遇到了一个奇怪的问题。我正在使用无限滚动,当加载图像时,它们会被附加两次。添加更多页面后,我今天注意到了这个问题。我真的不确定是什么原因造成的,但认为它与我的 jQuery 代码有关。我的代码如下。
(function(){
//masonry
$(function() {
var container = document.querySelector('.post_container');
var msnry = new Masonry( container, {
// options
itemSelector: '.post'
});
});
//images loaded
var $container = $('.post_container');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector : '.post'
});
});
$('.container').infinitescroll({
navSelector : "div.pagination",
// selector for the paged navigation (it will be hidden)
nextSelector : "#next a",
// selector for the NEXT link (to page 2)
itemSelector : '.post',
// selector for all items you'll retrieve
loading: {
finished: undefined,
finishedMsg: "<em>Congratulations, you've reached the end of the internet.</em>",
msg: null,
msgText: "<em>Loading the next set of posts...</em>",
selector: null,
speed: 'fast',
start: undefined
}
}, //callback to make the all work together
function(newitems) {
$container.append(newitems);
imagesLoaded(newitems, function(){
$container.masonry('appended', newitems);
$container.masonry('layout');
});
});
我已经仔细检查了我的 html,甚至将其删除并一次检查每个图像。由于某种原因,插件将图像附加了两次。
【问题讨论】:
标签: jquery plugins append jquery-masonry