我正在嘗試將聖誕燈加入我的徽標。我打算在Flash中這樣做,但我試圖擺脫閃存,所以我決定嘗試使用jQuery。jQuery按時間間隔更新圖像
快速谷歌搜索返回this tutorial。哪一個做得很好,讓我走上正軌。問題是,我不希望圖像淡入和淡出,所以我代替
$active.fadeOut(function() $next.fadeIn().addClass('active');
與 $ active.show(函數()$ next.show()addClass(「激活」)。
這樣做的問題是,它只是旋轉,雖然圖像一次,然後停止。我試圖用hide
代替,但它確實一個奇怪的縮小效果。
總之,我有4張圖片,我試圖循環使用此代碼:
function swapImages(){
var $active = $('#myGallery .active');
var $next = ($('#myGallery .active').next().length > 0) ? $('#myGallery .active').next() : $('#myGallery img:first');
$active.show(function(){
$active.removeClass('active');
$next.show().addClass('active');
});
}
$(document).ready(function(){
setInterval('swapImages()', 1000);
})
HTML:
<div id="myGallery">
<img src="br_xmas_1.png" class="active" />
<img src="br_xmas_2.png" />
<img src="br_xmas_3.png" />
<img src="br_xmas_4.png" />
</div>
See partly working full code here或不工作jsfiddle
你試過show()/ hide()而不是fadeIn()/ fadeOut()嗎? – macjohn
是的,這是我第一次嘗試。顯示很好,但隱藏使圖像縮小。它實際上看起來類正在被應用,它只是沒有正確隱藏圖像。 – BandonRandon