开发者

jquery how to make sure that all the images has been loaded

开发者 https://www.devze.com 2022-12-13 06:31 出处:网络
var nowCount = 0; $(\"img\").load(function(){ imgCount++; if (nowCount == imgsCount) do something ... });
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消