2012-03-04 4 views
0

일부 DIV를 정렬하기 위해 jQuery 플러그인 "Masonry"(http://masonry.desandro.com/)를 사용하고 있습니다. 이러한 DIV는 AJAX로로드되며 플러그인이 너무 일찍 시작되어 위치가 잘못되었습니다. 어떻게 이러한 기능에 적절한 지연을 설정할 수 있습니까?jQuery Masonry with 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(); 

는 위의 코드의 비는 시험 유의하시기 바랍니다. :). 도움이 될만한 기타 SO 링크 - link, link