我正在使用附加函数将元素附加到已初始化的砌体实例,但我的所有图块都在一列中排列,而且很多都是重叠的。你能看出我做错了吗?
function placeNewsTiles(news){ //places news tiles
var length = (news.data.length > 20) ? 20 : news.data.length;
var $container = $('#news');
var elems ="";
for(var i = 0; i < length; i++){
elems += '<div class="pageNewsItem" id="'+ count + i + '">\
<div class="textWrap">\
<a href="' + news.data[i]._url + '">\
<strong>' + news.data[i]._title + '</strong>\
</a>\
<span class="source">' + news.data[i]._source + '</span>\
</div>\
<div class="imageWrap"></div>\
<div class="thumbsOverlay" style="display:none">\
<div class="thumbs">\
<div>\
<a href="#"" class="up"><img src="../images/Thumbs-Up-2.png" /></a>\
<a href="#"" class="down"><img src="../images/Thumbs-Down-2.png" /></a>\
</div>\
</div>\
</div>\
</div>';
getTileImage({total: news.count, i:count + "" + i, url:news.data[i]._url});
}
elems = $(elems);
$('#news').append(elems).imagesLoaded(function(){
$('#news').masonry( 'appended', elems, true );
});
newsPage = 0;
count++;
hoverTiles();
}
$(document).ready(function() {
newClock();
readyLogin();
var $container = $('#news');
//$container.imagesLoaded( function() {
$container.masonry({itemSelector: '.pageNewsItem'});
//});
obtainSearchQuery();
});
答案 0 :(得分:0)
在此行中,尝试在附加项目后触发layout
:
$('#news').masonry( 'appended', elems, true ).masonry('layout');
我已经看过有或没有额外.masonry()
电话的示例,但它可能有用。