我試圖淡入/出div內的一些文本。爲了調試的目的,我已經把時間保持得很快。問題是我認爲淡入淡出是互相爭鬥的。有時文本進行更新,然後將其淡入/出...有一些setInterval + JQuery FadeIn/FadeOut問題
See this interactive example on jsFiddle
下面的代碼:
var tips = [
'AAA',
'BBB',
'CCC'
];
var currentTipIndex = 0;
setInterval(function() {
currentTipIndex++;
if (currentTipIndex >= tips.length) {
currentTipIndex = 0;
}
$("#pewpew").fadeOut(1000);
$("#pewpew").html(tips[currentTipIndex]);
$("#pewpew").fadeIn(1000);
}, 1 * 5 * 1000);
這就像要間隔計時器停止。然後淡出。 (等待淡出完成)。更新文本。淡入..(等待淡入開始)。然後再次啓動計時器。
任何人都可以幫忙嗎?
使用回調函數與淡出和淡入。見http://api.jquery.com/fadeIn/ – Stefan 2012-02-23 08:19:59