Animating “src” attribute

后端 未结 7 590
轮回少年
轮回少年 2020-12-11 21:39

I have an HTML document. It looks like this:

\"original\"

When the user hovers \"stackinfo\" image, I w

7条回答
  •  情书的邮戳
    2020-12-11 22:27

    You could animate the opacity to zero, use the callback to change the image source and bind an event handler for when the image loads that animates the opacity back.

    $('.sprite').on("mouseover",function(e){
        $(this).animate({
            opacity: 0
        },1000, function(){
            setTimeout(function(){
                $('.sprite').animate({
                    opacity: 1
                },1000);
            },50);
            $('.sprite').css("background","url(someurl)");
        });
    })
    

    See this example: http://jsfiddle.net/nHC9U/

提交回复
热议问题