Andresh Podzimovsky
Andresh Podzimovsky

Reputation: 1561

How to check if image is loaded?

Is it possible somehow to check is image loaded without function .load() or onLoad? Problem is that the webkit-like browsers doesn't work properly with this function.

UPDATE: Problem is in http://en.wikipedia.org/wiki/Motion_JPEG - load fires only once otherwise stream is going and loading new images.

Upvotes: 0

Views: 7165

Answers (2)

Denys Séguret
Denys Séguret

Reputation: 382474

You can check img.width : it's 0 if it's not loaded.

But I'm sure you can use onload (all low cap) on webkit browsers too :

 img.onload=function(){
     console.log('loaded!');
 };
 img.src='something';

Beware a frequent error : you have to set the src after you set the onload, or the onload callback won't be called if the image is in cache.

Demonstration : tested on Chrome, which is webkit based

Upvotes: 4

kannix
kannix

Reputation: 5167

I used this https://github.com/desandro/imagesloaded in a project and it worked fine for me

Upvotes: 3

Related Questions