-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountdown.js
30 lines (23 loc) · 992 Bytes
/
countdown.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var minutesTotal = 15 * 60;
var countDownDate = new Date(
new Date().getTime() + minutesTotal * 1000
).getTime();
var x = setInterval(function () {
var now = new Date().getTime();
var distance = countDownDate - now;
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
var secondsLeft = ((distance % (1000 * 60 * 60)) / 1000 / minutesTotal) * 100;
var minutesDisplay = minutes < 10 ? `0${minutes}` : minutes;
var secondsDisplay = seconds < 10 ? `0${seconds}` : seconds;
document.getElementById("eta").innerHTML =
minutesDisplay + ":" + secondsDisplay;
document.getElementById("done").style.width = `${100 - secondsLeft}%`;
if (distance < 0) {
clearInterval(x);
document.getElementById(
"eta"
).innerHTML = `<p style="color: #aa0000">Something went wrong! Please, try again later</p>`;
document.getElementById("spinner").style.animation = "none";
}
}, 1000);