我有一个脚本:
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 专家,但我渴望成为一名 js 专家。
最佳答案
在递减计数器之前设置条形尺寸:
jQuery('#bar').css('width', intCount * intTickLength + 'px');
jQuery('#timer').html('00:0' + intCount--);
关于javascript - setInterval 计时器需要在动画进度条上进行偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12335030/