[英]Clear timer using clearInterval is not working
我把我的工作放在網上:
如何重現:
在畫布上簽名
您應該會看到一個從 20:00 開始的計時器
我的計時器在文件 /js/timer.js 我不明白為什么,因為當我調用按鈕第 59 行時,我清除了this.setTimer
,我使用timer.cancel
方法來 clearInterval 並清除 sessionStorage。 但是我嘗試調試和奇怪的事情, this.setTimer
似乎等於10,然后我每次取消時, this.setTimer
增加1。
我錯過了什么 ? 正確的行為應該是當我點擊“annule”(取消)計時器重置為 20:00 分鍾
這是我的取消功能
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
減去 1000 時存儲舊值。
在清除間隔后,您需要再次重置this.delta
值。 嘗試添加
this.delta = (this.endDate - this.now);
后
clearInterval(this.setTimer);
在取消方法中。
希望我回答了你的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.