将jQuery与AJAX结合使用
我正在使用jQuery插件“砌体”(http://masonry.desandro.com/)整理一些div。这些div都加载了AJAX,不知怎的,插件启动得太早,位置也错了。 如何在这些函数中设置适当的延迟将jQuery与AJAX结合使用,jquery,ajax,plugins,Jquery,Ajax,Plugins,我正在使用jQuery插件“砌体”(http://masonry.desandro.com/)整理一些div。这些div都加载了AJAX,不知怎的,插件启动得太早,位置也错了。 如何在这些函数中设置适当的延迟 function loadALLtheposts(id) { $.ajax({ url: "******.php", data: {userID: id}, type: "POST", dataType: "text", contentType: "
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
});
}
提前感谢。您应该使用标准的DOM事件-domsubtreemedited(已弃用) 改用 请注意,以上代码中的任何部分都经过测试。:)。其他可能有用的SO链接-
$("#timeline-posts").bind("DOMSubtreeModified", function() {
masonry_index(); //this is called only after the #timeline-posts changes.
$(this).unbind('DOMSubtreeModified'); //if required do this
});
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();