Jquery 在重置前将超时添加到倒计时
我正在用这个做一个简单的倒计时,当它达到零时显示随机数。代码运行良好,只是想在再次启动前增加3秒的延迟 希望你能帮助我 谢谢Jquery 在重置前将超时添加到倒计时,jquery,Jquery,我正在用这个做一个简单的倒计时,当它达到零时显示随机数。代码运行良好,只是想在再次启动前增加3秒的延迟 希望你能帮助我 谢谢 让时间=10; 让进度=0;设计数器=0 变量时钟=$('.my clock')。FlipClock(时间{ 倒计时:没错, 计数:1, 回调:{ 停止:函数(){ setTimeout(函数(){ clock.setTime(time);//正在进行的时间 clock.start(); for(设i=0;i=100){ 进度=0;计数器=0; 这个 } } } });
让时间=10;
让进度=0;设计数器=0
变量时钟=$('.my clock')。FlipClock(时间{
倒计时:没错,
计数:1,
回调:{
停止:函数(){
setTimeout(函数(){
clock.setTime(time);//正在进行的时间
clock.start();
for(设i=0;i<5;i++){
var arresult=[];
setTimeout(函数(){
var r=Math.floor(Math.random()*11)+1;
arresult.push(r);
setTimeout(函数(){
$('.numResult div:nth child('+(i+1)+')).html(arresult[i]);
},200);
如果(arresult.length==5){
$('.results ul').append(''+arrsult+' ');
}
},500*i);
}
},1000);
},
间隔:函数(){
计数器&(进度+=100/次);
计数器++;
$('.progressBar.progress').width(progress+'%');
如果(进度>=100){
进度=0;计数器=0;
这个
}
}
}
});
试着让您的第一次设置超时
只换行时钟.setTime
和时钟.start
让时间=10;
让进度=0;设计数器=0
变量时钟=$('.my clock')。FlipClock(时间{
倒计时:没错,
计数:1,
回调:{
停止:函数(){
setTimeout(函数(){
clock.setTime(time);//正在进行的时间
clock.start();
},3000);
for(设i=0;i<5;i++){
var arresult=[];
setTimeout(函数(){
var r=Math.floor(Math.random()*11)+1;
arresult.push(r);
setTimeout(函数(){
$('.numResult div:nth child('+(i+1)+')).html(arresult[i]);
},200);
如果(arresult.length==5){
$('.results ul').append(''+arrsult+' ');
}
},500*i);
}
},
间隔:函数(){
计数器&(进度+=100/次);
计数器++;
$('.progressBar.progress').width(progress+'%');
如果(进度>=100){
进度=0;计数器=0;
这个
}
}
}
});代码>
。我的时钟{
文本对齐:居中;
宽度:自动;
显示:内联块;
}
.中心{
文本对齐:居中;
}
.progressBar{
保证金:0自动;
宽度:400px;
高度:6px;
边界半径:3px;
背景色:#222;
}
.进展{
背景颜色:绿色;
身高:100%;
宽度:100%;
}
努姆雷索分区{
显示:内联块;
}
.结果{
宽度:50px;
位置:绝对位置;
左:0;
右:0;
保证金:0自动;
}
.结果ul{
填充:0;
}
听起来像是setInterval
而不是setTimeout
let time = 10;
let progress = 0; let counter = 0
var clock = $('.my-clock').FlipClock(time, {
countdown: true,
count: 1,
callbacks: {
stop: function() {
setTimeout(function(){
clock.setTime(time); // proceeding time
clock.start();
for (let i = 0; i < 5; i++) {
var arrResult = [];
setTimeout(function(){
var r = Math.floor(Math.random() * 11) + 1;
arrResult.push(r);
setTimeout(function(){
$('.numResult div:nth-child('+ (i+1) +')').html(arrResult[i]);
},200);
if(arrResult.length === 5){
$('.results ul').append('<li>'+ arrResult +'</li>');
}
},500 * i);
}
},1000);
},
interval: function() {
counter && (progress+=100/time);
counter ++;
$('.progressBar .progress').width(progress+ '%');
if(progress >= 100) {
progress = 0; counter = 0;
this.stop()
}
}
}
});