2012-03-04 17 views
0

私はいくつかのDIVをソートするためにjQueryプラグイン "Masonry"(http://masonry.desandro.com/)を使用しています。これらのDIVにはAJAXがロードされていて、何とかしてプラグインが早すぎて開始位置が間違ってしまいます。 これらの機能に適切な遅延を設定するにはどうすればよいですか?jQuery MasonryをAJAXで使用する

function loadALLtheposts(id) { 
$.ajax({ 
    url: "******.php", 
    data: {userID: id}, 
    type: "POST", 
    dataType: "text", 
    contentType: "application/x-www-form-urlencoded; charset=utf-8", 
    success: function (data) { 
     $('#timeline-posts').html(data); 
     masonry_index(); 
    } 
}); 
} 

function masonry_index() { 
$('#timeline-posts').masonry({ 
    itemSelector : '.post-wrapper', 
    columnWidth : 266 
}); 
} 

ありがとうございます。 DOMSubtreeModified(非推奨)

$("#timeline-posts").bind("DOMSubtreeModified", function() { 
    masonry_index(); //this is called only after the #timeline-posts changes. 
    $(this).unbind('DOMSubtreeModified'); //if required do this 
}); 

使用MutationObservers代わりに -

答えて

0

あなたは、標準のDOMイベントを使用する必要があります。

var target = $('#some-id'); 
var observer = new MutationObserver(function(mutations, observer) { 
    //mutation occured 
    masonry_index(); 
}); 
var config = { attributes: true, childList: true, characterData: true }; //there are others that you can choose. Follow the link above. 
observer.observe(target, config); 
//if you want to stop observing 
observer.disconnect(); 

上記のコード以外はテストされていませんのでご注意ください。 :)。他の役に立つリンク - linklink

関連する問題