@Yariik
PHP, C#, JavaScript, jQuery, HTML, CSS

Как обновить время таймера?

При обновлении страницы срабатывает таймер, если пользователь нажимает на кнопку то время таймера нужно обновить в начальное
let t = 1000*5;
$('html').on('click', '.ApiOnline', function () {
        t = 1000*5;
})

setTimeout(function () {
	$('.status-on').css({'display':"none"})
}, t);
  • Вопрос задан
  • 592 просмотра
Пригласить эксперта
Ответы на вопрос 1
@Yariik Автор вопроса
PHP, C#, JavaScript, jQuery, HTML, CSS
Переделал сам
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)
})
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы