开发者

switching images using jquery

开发者 https://www.devze.com 2023-04-09 20:42 出处:网络
i can\'t get the following code to work: $(\'#clicked_package\').css({\"background-image\" : \"url(img/head_2.png)\"}).fadeOut(\"slow\");

i can't get the following code to work:

$('#clicked_package').css({"background-image" : "url(img/head_2.png)"}).fadeOut("slow");
$('#clicked_package').css({"background-image" : "url(img/head_2_normal.png)"}).fadeIn("slow");

Regardless of what image I put开发者_运维百科 in the first line, It always seems to replace it with the second line. So my first image is the same as the second image.

What i want is to fade out the first image, and then fade in a second image.

suggestions? thanks


You probably want the version of fadeOut that accepts a callback function:

$('#clicked_package')
    .css({"background-image" : "url(img/head_2.png)"})
    .fadeOut("slow", function () {
        $(this).css({"background-image" : "url(img/head_2_normal.png)"})
            .fadeIn("slow");
});

Example: http://jsfiddle.net/andrewwhitaker/VLRKy/

0

精彩评论

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

关注公众号