开发者

Determining when images load in HTML?

  1. Is there a way to determine when a specific image asset has been loaded, either in a tag or as a background?
  2. Is there a way to determine when ALL ima开发者_如何转开发ges in a page have been loaded?

If not, are there any jquery//alternative image loading techniques that would enable this?

Thanks


1) Use the onload event handler.

2) Use the onload event to increment a variable imagesloaded by 1, when imagesloaded == document.getElementsByTagName('img').length then all images have loaded

You may want to also use the onerror event, which fires when an image fails to load (for any reason), along with onabort for when the user aborts the connection.


Handle the onload event of the (1) image or (2) window.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜