Animating “src” attribute

后端 未结 7 589
轮回少年
轮回少年 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:21

    You can't animate the .src value directly with jQuery.

    You will need to use two images, positioned on top of one another so one can be faded in on top of the other.

    Both images should be preloaded or precached so there is no delay for an image to load after setting .src.

    Working example: http://jsfiddle.net/jfriend00/n52Fr/

    $(".container").hover(function() {
        $(this).find(".fadeTop").fadeOut(1000);
    }, function() {
        $(this).find(".fadeTop").fadeIn(1000);
    });​
    
    
    
    ​ .container { position: relative; height: 100px; width: 150px; } .container img { position: absolute; top: 0; left: 0; }

提交回复
热议问题