forked from codeSTACKr/nft-landing-page
-
Notifications
You must be signed in to change notification settings - Fork 0
/
countdown.js
24 lines (22 loc) · 889 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
//Countdown Timer
const clockdiv = document.getElementById("countdown");
const countDownTime = new Date(
clockdiv.getAttribute("data-date")
).getTime();
const countdownfunction = setInterval(function () {
const now = new Date().getTime();
const diff = countDownTime - now;
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
const hours = Math.floor(diff % (1000 * 60 * 60 * 24) / (1000 * 60 * 60));
const minutes = Math.floor(diff % (1000 * 60 * 60) / (1000 * 60));
const seconds = Math.floor(diff % (1000 * 60) / 1000);
if (diff < 0) {
clockdiv.style.display = "none";
clearInterval(countdownfunction);
} else {
clockdiv.querySelector(".days").innerHTML = days;
clockdiv.querySelector(".hours").innerHTML = hours;
clockdiv.querySelector(".minutes").innerHTML = minutes;
clockdiv.querySelector(".seconds").innerHTML = seconds;
}
}, 1000);