jquery how to make sure that all the images has been loaded
var nowCount = 0;
$("img").load(function(){
imgCount++;
if (nowCount == imgsCount)
do something ...
});
imgsCount :: the number of images that i want 开发者_StackOverflow中文版to load
1- is this code compatible with all browsers ?
2- how can i know if an image failed to load ?There is a lot of suspicious code here:
- ImgsCount vs. ImgCount
- what is
nowCount
supposed to do? - Are you sure about the
unload
event for the IMG tag?
If you want to load images in the background, you need to create a new image element and attach a source attribute.
精彩评论