Answer the question
In order to leave comments, you need to log in
How to update timer time?
When the page is refreshed, a timer is fired, if the user clicks on the button, then the timer time needs to be updated to the initial
let t = 1000*5;
$('html').on('click', '.ApiOnline', function () {
t = 1000*5;
})
setTimeout(function () {
$('.status-on').css({'display':"none"})
}, t);
Answer the question
In order to leave comments, you need to log in
Remade by myself
class dynamicTimer {
constructor(func, delay) {
this.callback = func
this.triggerTime = delay
this.timer = 0
this.updateTimer()
}
updateTimer() {
clearTimeout(this.timer)
let delay = this.triggerTime
// console.log("Current delay: ", delay)
this.timer = setTimeout(this.callback, delay)
return this
}
addTime(delay) {
this.triggerTime = delay
this.updateTimer()
return this
}
}
let timer = new dynamicTimer(function() {
$('.status-on').css({'display':"none"})
}, 3000)
$('html').on('click', '.ApiOnline', function () {
timer.addTime(3000)
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question