【发布时间】:2017-03-08 16:17:21
【问题描述】:
我有一个运行良好的秒表,但在 60 秒后的秒值我需要计时器变为零,分钟到 1,并且以同样的方式每 60 秒分钟应该改变
/* Stopwatch */
starttime(){
console.log("timer started");
if( this.running == 0){
this.running = 1;
this.adder()
}else{
this.running = 0;
}
}
reset(){
console.log("timer reset");
this.running = 0;
this.time = 0;
this.total = 0;
this.Sec = 0;
}
adder(){
console.log("timer incrementor");
if(this.running == 1){
setTimeout(()=>{
this.time++;
var mins = Math.floor(this.time/10/60);
var sec = Math.floor(this.time / 10 );
var tens = this.time/10;
this.total = mins + ':' + sec;
console.log(this.total) ;
this.Sec = sec;
this.adder()
},10)
}
}
但是这里时间发生了变化,秒被加起来,当它达到 60 时它不会变为零它移动到 61,62,63.... 120 秒后的采样时间是 0:2:120,我需要什么是 0:2:0(小时:秒:分钟)
修改'var sec = Math.floor(this.time / 10)%60;'后工作正常并将设置超时时间更改为
this.adder()
},100)
【问题讨论】:
标签: javascript typescript