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 images in a page have been loa
Solution 1:
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.
Solution 2:
Handle the onload
event of the (1) image or (2) window.
Post a Comment for "Determining When Images Load In HTML?"