Sunday, August 29, 2010

Wait till a dynamically loaded image fully load using jQuery

I had this problem when I was creating simple jQuery gallery with thumbs. Once the thumb is clicked I wanted to wait till the image is fully loaded until I called the fadeIn.
we can use jQuery load to achieve this.

$('#image').attr("src", image); //next image path
//still in hide
$('#image').load(function() {    


  1. does this mean that this script will wait for the image to be fully loaded and rendered?

  2. yes, load function will wait till the image is fully loaded

  3. Great post, this helped, although I switched the define load function before I set the image source. This prevents a race condition. Just a suggestion :)

    $(img).load(function() {...});