generated from goitacademy/vanilla-app-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from konstantin-it-lysenko/Add-Timer
Timer-Favourites-Anatolii
- Loading branch information
Showing
6 changed files
with
192 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
document.addEventListener('DOMContentLoaded', function () { | ||
const timerValue = document.getElementById('timerValue'); | ||
const startListItem = document.getElementById('startTimerListItem'); | ||
const timerStart = document.querySelector('.favor-dailynorm-icon'); | ||
let timerInterval; | ||
let timerActive = false; | ||
|
||
function startTimer(duration, display) { | ||
if (timerActive) { | ||
return; | ||
} | ||
|
||
timerActive = true; | ||
display.style.display = 'block'; | ||
|
||
startListItem.setAttribute('data-active', 'true'); | ||
|
||
let timer = duration, | ||
minutes, | ||
seconds; | ||
display.textContent = '110:00'; | ||
|
||
timerInterval = setInterval(function () { | ||
minutes = parseInt(timer / 60, 10); | ||
seconds = parseInt(timer % 60, 10); | ||
|
||
minutes = minutes < 10 ? '0' + minutes : minutes; | ||
seconds = seconds < 10 ? '0' + seconds : seconds; | ||
|
||
timerValue.textContent = minutes + ':' + seconds; | ||
|
||
if (--timer < 0) { | ||
clearInterval(timerInterval); | ||
timerValue.textContent = '00:00'; | ||
timerActive = false; | ||
startListItem.setAttribute('data-active', 'false'); | ||
} | ||
}, 1000); | ||
} | ||
|
||
startListItem.addEventListener('click', function () { | ||
startTimer(6600, timerValue); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.