我有一个容器#boxes
我需要清空并添加内容以使用.imagesLoaded()
然后应用砌体。默认情况下,内容包含我正在删除的砌体项目,然后添加响应中包含的新项目。我的代码存在的问题是,在我相信追加后,它会清空内容。有什么想法吗?
$(document).ready(function($){
$('div.profile-archive').click(function(){
$("#boxes").empty();
$this = $(this);
var postType = $this.attr("rel");
data = {
action: 'fetch_profile_archive',
postType : postType
};
$.post(ajaxurl, data, function (response) {
var $response = $(response);
$response.imagesLoaded(function() {
$("#boxes").masonry('reload');
}).appendTo("#boxes");
});
});
});
答案 0 :(得分:0)
我认为你的问题在于imagesloaded
功能。您目前将imagesloaded
的结果附加到boxes
,我猜您首先将回复添加到boxes
,然后在imagesLoaded
上运行boxes
。
$("#boxes")
.append($response)
.hide() // If you don't want to show the content until loaded
.imagesLoaded(function() {
$("#boxes")
.show() // If you want to show the content after it's loaded
.masonry('reload');
});