views:

37

answers:

1

I would like to set up a lean and mean image gallery, with thumbnails displayed inline. I'd like them not to windowshade in while loading, I'd like them to simply pop up or, if there's a way to detect their completion, use a jQuery effect like a quick fadeIn().

I imagine a line of code like:

$(".thumb-image").whenLoaded(fadeIn(500));

But is there such an event? What's it called?

+1  A: 

Use the load event:

jQuery:

$(window).load(function(){
  // your code for images....
});

Or Vanilla JavaScript:

window.onload = function(){
  // your code for images....
};

The load event fires after all images, DOM, external resources, frames, etc have loaded.

Sarfraz
Thanks, sAc, I checked the jQuery reference and yes you can attach this to any selector. Neato.
Isaac Lubow
Interestingly, there is a plugin that triggers the load event for cached images as well, in situations where the browser fails to do so...http://github.com/peol/jquery.imgloaded/raw/master/ahpi.imgload.js
Isaac Lubow