2013-02-19 41 views
1

不知道爲什麼這是不工作,但我有它加載的數字像這樣一個計時器:淡入動態文本

function startTimer(num){ 
    count = num; 
    countdown = setInterval(function(){ 

    $("#timer p.seconds").text([count]).fadeIn(300); 
    count--; 
    }, 1000); 
}; 

$(document).on('click', '.step3-btn', function(e){ 
    e.preventDefault(); 
    startTimer(30); 
}); 

<p class="seconds"></p> 

我想最初的數量慢慢淡出,但代碼不起作用。它只是顯示沒有褪色。

+1

請張貼一個完整的代碼示例。 – j08691 2013-02-19 14:54:53

+0

好吧,我剛剛添加了更多的代碼 – user1937021 2013-02-19 14:59:06

+0

你有沒有試過在'.fadeIn(300)'之前放一個'.hide()'? '(「#timer p.seconds」)。text([count])。hide()。fadeIn(300);' – j08691 2013-02-19 15:06:10

回答

1

只是檢查,看是否第一個數字是上限,只淡入通過先隱藏它。

jsFiddle example

function startTimer(num) { 
    count = num; 
    countdown = setInterval(function() { 
     if(count==num){$("p.seconds").text([count]).hide().fadeIn(300);} 
     else{$("p.seconds").text([count]).fadeIn(300);}   
     count--; 
    }, 1000); 
}; 
startTimer(30); 
1

小提琴這裏,http://jsfiddle.net/pqUYS/

var count = 10, 
    next; 
(next = function() { 
    if (count > 0) { 
     $("p.seconds").hide().text(count--).fadeIn(1000, next); 
    } 
})(); 

更新小提琴

只有消失在第一號 http://jsfiddle.net/pqUYS/3/

+0

謝謝,但我只想淡入初始數字,而不是每個數字。 – user1937021 2013-02-19 15:10:49