show loading gif of image only if it is really loading it for the first time

Posted by Y.G.J on Stack Overflow See other posts from Stack Overflow or by Y.G.J
Published on 2010-03-09T09:03:25Z Indexed on 2010/03/09 9:06 UTC
Read the original article Hit count: 315

Filed under:
|
|

i have 2 img elements. 2 id's for them: rimg and limg. limg is the loading gif and rimg is the reloaded full vertsion of the image.

the is the code to show the loading before image finish to load:

$("#limg").fadeIn("fast");
$("#rimg").attr("src",$(that).attr("bsrc")).load(function(){
    $("#limg").fadeOut("fast",function () {
        $("#rimg").attr("alt",$(that).attr("alt"));
        $("#rimg").fadeIn("normal");
});
});

if i log into the site for the first time, it shows me the loading gif. if it is not my first time it is still showing that but i need the loading to be smooth without that loading how can i check if the image is loaded and cached before showing the loading gif?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about preload