tags:

views:

30

answers:

1

I am using this function to fadeout the old image on click and then fade in new image

$("#left_img img").fadeOut(1000, function() {

    $(this).attr("src","/image/p2r.gif").fadeIn(500);

});

The problem is when first image is faded out then before the new image fades in , the first image loads again for 1 second and then new image fades in

A: 

It sounds like the image hasn't fully loaded, try adding an event listener to it to fade it in once it's loaded, like so:

$("#left_img img").fadeOut(1000, function() {

    $(this).attr("src","/image/p2r.gif").load( function() {
        $(this).fadeIn(500);
    });

});

Edit: My apologies, that should be "load" instead of "ready." Not to be confused with the load() function for AJAX.

Zack
This is working but don't understand what was the problem
Mirage
When you set the src to a different image, the image must be loaded; while it's loading the old image is still displayed. This adds an event listener for when the image has finished loading.
Zack