0

石積み#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");
        });
    });

});
4

1 に答える 1

0

あなたの問題はimagesloaded機能にあると思います。あなたは現在 からimagesloadedへの結果を追加していますが、最初に への応答を追加してから で実行したboxesと思います。boxesimagesLoadedboxes

$("#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');
  });
于 2012-10-16T17:06:23.580 に答える