0
我正在尝试淡入和淡入淡出图像和gif之间的转换,因为它们已交换。我试着用不透明的CSS3过渡,但它将GIF淡化为无。我曾尝试使用fadeIn()jQuery函数,但我没有成功。有人可以帮助/指向正确的方向吗?将Fadein Fadeout添加到图像交换函数
代码:
html
<figure>
<img src="http://reneinla.com/tasha/style/images/stills/FORD-SUPER-BOWL.jpg" data-alt-src="http://reneinla.com/tasha/style/images/gifs/giphy.gif"/>
</figure>
<figure>
<img src="http://reneinla.com/tasha/style/images/stills/OPERATOR.jpg" data-alt-src="http://reneinla.com/tasha/style/images/gifs/giphy.gif"/>
</figure>
<figure>
<img src="http://reneinla.com/tasha/style/images/stills/OPERATOR.jpg" data-alt-src="http://reneinla.com/tasha/style/images/gifs/giphy.gif"/>
</figure>
<figure>
<img src="http://reneinla.com/tasha/style/images/stills/FORD-SUPER-BOWL.jpg" data-alt-src="http://reneinla.com/tasha/style/images/gifs/giphy.gif"/>
</figure>
javascript:
var sourceSwap = function() {
var $this = $(this);
var newSource = $this.data('alt-src');
$this.data('alt-src', $this.attr('src'));
$this.attr('src', newSource);
}
$(function() {
$('img[data-alt-src]').each(function() {
new Image().src = $(this).data('alt-src');
}).fadeIn().hover(sourceSwap, sourceSwap);
});
谢谢!
你还需要咨询的吗? – Axel