Determining when images load in HTML?
- Is there a way to determine when a specific image asset has been loaded, either in a tag or as a background?
- 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.
精彩评论