I have made a little plugin where I get the size using naturalHeight
and naturalWidth
Sometimes when loading page I get 0 in width and height (other times it works fine). I guess it is because it calculate the size before loading the image.
How can I correct this?
I have tried to run plugin $("selector").myplugin()
inside $(document).ready
, but that doesn't change anything
I have also tried to wrap setTimeout
around the variables where I am using naturalHeight
and naturalWidth
, but that doesn't prevent rest of the code to run - and I won't make it slower loading than necessary (wrap everything in setTimeout
if not necessary)
So my question - are there a way to
- if size is 0 - wait a little and try again
- Not continue running rest until it is not 0 anymore
Or does anyone have another solution?