我想在第二张图片上制作fadeIn和fadeOut,但不知道在哪里写函数
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.xyz').hover(sourceSwap, sourceSwap);
}) ;

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img class="xyz" data-alt-src="img/map.jpg" src="img/colourmap.jpg" width="95%" />
&#13;
答案 0 :(得分:0)
试试这个
$('.xyz').fadeIn(1500).delay(0).fadeOut(1500);
$('.xyz').delay(1000).fadeIn(1500);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img class="xyz" data-alt-src="img/map.jpg" src="http://www.apicius.es/wp-content/uploads/2012/07/IMG-20120714-009211.jpg" width="50%" />
&#13;