开发者

How to check if images are being preloaded?

开发者 https://www.devze.com 2023-04-13 08:53 出处:网络
I wa开发者_StackOverflownt to preload an image with javascript, the method below seems simple enough but how can I check if the image has preloaded? Thanks

I wa开发者_StackOverflownt to preload an image with javascript, the method below seems simple enough but how can I check if the image has preloaded? Thanks Preloading images with jQuery


I would suggest modifying the code to add on 'onerror' event handler to the img tags you are generating. and then handle any failures.

http://www.w3schools.com/jsref/event_onerror.asp


Make a log entry in your image's "onload" event.

myImage.onload = function(){

   console.log("Image Loaded!");

}

If you're not familiar with chrome's developer tools or firefox's Firebug plugin, you should check them out. They make things like this a breeze.

Also, keep in mind that some browsers require the image.src attribute to be defined after the .onload event.

0

精彩评论

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

关注公众号