Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for a particular image to load completely using jquery?

I am currently using the code below to load images but I want to show some kind of loading gif before the image loads completely.

$('#addimage').attr('src', src[i]);
$('#addimage').show();

Since I am using this in a animated mediabox the image loading in blocks does not look good so by the time the image is loading I want to replace it by showing a loading gif. Thanks

like image 615
halocursed Avatar asked Jan 24 '10 23:01

halocursed


1 Answers

Use the load() event:

$("#addimage").load(function() {
  $(this).show();
});

Edit: to show one image until another loads is a little more convoluted but entirely possible. See Image Loading.

like image 151
cletus Avatar answered Oct 20 '22 01:10

cletus