[英]Clear timer using clearInterval is not working
I put my work online here :我把我的工作放在网上:
how to reproduce :如何重现:
Sign the canvas在画布上签名
You should see a timer starting 20:00 min您应该会看到一个从 20:00 开始的计时器
My timer is in the file /js/timer.js I don't understand why, because I clearInterval my this.setTimer
when I call the button line 59, I used timer.cancel
method to clearInterval and clear the sessionStorage.我的计时器在文件 /js/timer.js 我不明白为什么,因为当我调用按钮第 59 行时,我清除了
this.setTimer
,我使用timer.cancel
方法来 clearInterval 并清除 sessionStorage。 But I tried to debug and weird things, this.setTimer
appears to be equal to 10, then each time I cancel, this.setTimer
increases by 1.但是我尝试调试和奇怪的事情,
this.setTimer
似乎等于10,然后我每次取消时, this.setTimer
增加1。
Did I miss something ?我错过了什么 ? The proper behavior should be when I click on "annule" (cancel) the timer reset to 20:00 min
正确的行为应该是当我点击“annule”(取消)计时器重置为 20:00 分钟
Here my cancel function这是我的取消功能
cancel = () => {
this.isPlaying = false;
clearInterval(this.setTimer);
sessionStorage.clear();
console.log(this.setTimer);
canvas.clear();
this.timer.innerHTML = 'Votre réservation a été annulée.'
document.getElementById('reservation-content').classList.remove('hidden');
document.getElementById('cancel-btn').className = 'hidden';
document.getElementById('validation-btn').setAttribute('disabled', null)
}
this.delta
stores old value when you subtracted 1000.减去 1000 时存储旧值。
after clear interval you need to reset this.delta
value again.在清除间隔后,您需要再次重置
this.delta
值。 Try adding尝试添加
this.delta = (this.endDate - this.now);
after后
clearInterval(this.setTimer);
in cancel method.在取消方法中。
Hope I answered your question.希望我回答了你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.