Is it possible to find whether all the images are loaded in ajax content? I have used
var img = $('#slider img');
var length = img.开发者_JAVA技巧length;
img.load(function(){
length--;
if(length === 0){
alert("All images loaded");
};
});
but the load is not working, it is not goning in to the loop...
Try something like this.
$('#slider img').each(function() {
//Write pre loading script
});
You need add event listener load before set up src attribute. Or you can scan images and check if every is loaded (by image size):
var img = $('#slider img');
var length = img.length;
img.each(function(){
if ($(this).width() > 0 && $(this).height() > 0)
length--;
if(length === 0){
alert("All images loaded");
};
});
I not checked code.
精彩评论