2012-09-08 27 views
1

上抵消我有一個腳本:的setInterval定時器需要動畫的進度條

http://jsfiddle.net/bXJhe/7/

jQuery(document).ready(function() { 

    timer(10) 

}); 

// Timer 
var GLOBAL_TIMER; 

function timer(intCount) { 
    GLOBAL_TIMER = setInterval(function() { 

     var intTickLength = 10; 

     if (intCount < 10) { 
      jQuery('#timer').html('00:0' + intCount--); 
      jQuery('#bar').css('width', intCount * intTickLength + 'px'); 
     } else { 
      jQuery('#timer').html('00:' + intCount--); 
      jQuery('#bar').css('width', intCount * intTickLength + 'px'); 
     } 

     if (intCount < 0) { 
      stopTimer(); 
     } 

    }, 1000); 
} 

function stopTimer() { 
    clearInterval(GLOBAL_TIMER); 
}​ 

我動畫的進度條的基礎上,intCount * intTickLength(也許有一個更好的辦法寬度?)

問題是,當計數器達到1時,條上的最後一個記號消失。我需要它保持,直到計數器達到0.我需要某種抵消..任何想法?我不是js專家,但我渴望成爲一名專家。

回答

4

你遞減計數器之前設置鋼筋尺寸:

jQuery('#bar').css('width', intCount * intTickLength + 'px'); 
jQuery('#timer').html('00:0' + intCount--); 
+0

美麗。非常感謝。 – Scott