2012-10-16 25 views
0

我有一个容器#boxes,我需要清空和添加内容使用.imagesLoaded(),然后应用砌筑烧制。内容默认包含我正在删除的砌体项目,然后添加包含在响应中的新项目。我的代码存在的问题是,在我相信追加内容后,它会清空内容。有任何想法吗?.appendTo之前空容器()被使用jQuery

$(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

我认为你的问题在于imagesloaded函数。您目前的结果,从追加到imagesloadedboxes,我的猜测是,你有响应添加到boxes第一,然后在boxes运行imagesLoaded

$("#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'); 
    }); 
+0

当我做到这一点的内容出现,然后消失。 –

+0

好吧,算了一下。在'imagesLoaded'里面,我们只需要应用'.show().masonry('reload')',它工作正常。如果你同意更新你的答案,我会接受它。 –

+0

我编辑了你的原代码和我的'.masonry('reload')',以便它们匹配。 – Jan