How to wait for an image to be loaded?


I’m making a simple gallery, which uses simple javascript for changing
‘src’ attrbiute of ‘img’ element.

How to wait for an image to be downloaded completely before trying to
display it and while browser downloads this image display a spinner gif
or ‘please wait’ message etc.?

Something like this:

szymek wrote:

This should work, but I haven’t had cause to try it… Load the
high-res image into a hidden img tag, whose onload handler swaps the
spinner’s src attribute for its own. Alternatively, if you’ve got
control over the images, you could be polite to your users and use an
interlaced file format. Not as Web2.0, but much, much cleaner.

Place the img tag in a div with a spinner as background???

On Friday, April 07, 2006, at 11:26 AM, Alex Y. wrote:

Something like this:
Rails mailing list
[email protected]

Mikkel B. - Football Portal(DK) - Buy Old Stuff!(DK)

Thanks, i didn’t know that img handles onload event.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs