setInterval计时器需要在动画进度条上偏移 [英] setInterval timer need offset on animated progress bar
本文介绍了setInterval计时器需要在动画进度条上偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个脚本:
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
对进度条的宽度进行动画处理(也许有更好的方法吗?)
I'm animating the width of the progress bar based on the intCount
* intTickLength
(maybe there's a better way?)
问题是,当计数器达到1时,条上的最后一个刻度消失.我需要一直保持下去直到计数器达到0.我需要某种偏移量..有什么想法吗?我不是js专家,但我很想成为一个.
Problem is, when the counter reaches 1, the last tick on the bar disappears. I need it to remain until counter reaches 0. I need some kind of an offset.. Any ideas? I'm no js expert, but I long to be one.
推荐答案
在递减计数器之前设置小节大小:
Set the bar size before you decrement the counter:
jQuery('#bar').css('width', intCount * intTickLength + 'px');
jQuery('#timer').html('00:0' + intCount--);
这篇关于setInterval计时器需要在动画进度条上偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文