I am running a script which loads images and data from a ajax request and then displays it in my Blocksit gallery (a jquery plugin for a masonary gallery). The problem divs are being created before the images a actually loaded so they do not place correctly on the gallery. I need to somehow hold the data, load it, then run the function to display the gallery. I have tried using a setTimout, but no luck there obviously. here is my code:
("#loadMore").click(function(){
$.ajax({
url: "loadMore.php",
data: {count: count,
type: type},
type: "POST",
success: function(html){
var data = jQuery.parseJSON(html);
if (data.html == "stop"){
}
else{
setTimeout(function() {
$('#container').append(data.html);
$('#container').BlocksIt({
numOfCol: 3,
offsetX: 5,
offsetY: 5
});
}, 2000);
$('html, body').animate({ scrollTop: $(document).height()-$(window).height() }, 500, "linear");
count = $(".grid").length;
}
}
});
});
Any help is greatly appreciated :)