开发者

Jquery fadeout function redraws old image

开发者 https://www.devze.com 2022-12-29 03:07 出处:网络
I am using this function to fa开发者_Go百科deout the old image on clickand then fade in new image

I am using this function to fa开发者_Go百科deout 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消