-1

Possible Duplicate:
How to show a spinner while loading an image via JavaScript

I have an img, next btn and previous btn

Next button loads next image as

crntSrc=$("img").attr('src');
nextSrc=(crntSrc+1);
$("img").attr('src',nextSrc);

but I want to show process.gif image until nextSrc completely loads.

Community
  • 1
  • 1
sneha khan
  • 69
  • 1
  • 7

2 Answers2

1

You could try to set the process.gif as background of your image in css:

​img{
 background:url('process.gif') no-repeat center;   
}

​

Andy
  • 29,707
  • 9
  • 41
  • 58
1

You can do something like this:

function preload(src, cb)
{
    var img = new Image();
    img.load = cb;
    img.src = src;
}

var newImage = "/foo/foo.jpg";

// Function is called after image is loaded into memory.
preload(newImage, function(){
    $("#afterloadimg").attr("src", this.src);
});
Niels
  • 48,601
  • 4
  • 62
  • 81