deadlines
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
let timer = null;
|
||||
function startCountdown(dateString) {
|
||||
if (timer) clearInterval(timer);
|
||||
let cd = document.getElementById("countdown")
|
||||
if (cd) {
|
||||
cd.classList.remove("hide");
|
||||
if (dateString == "None") cd.classList.add("hide");
|
||||
}
|
||||
const end = new Date(dateString).getTime();
|
||||
const dayEl = document.getElementById('days');
|
||||
const hoursEl = document.getElementById('hours');
|
||||
const minutesEl = document.getElementById('minutes');
|
||||
const secondsEl = document.getElementById('seconds');
|
||||
const seconds = 1000;
|
||||
const minutes = seconds * 60;
|
||||
const hours = minutes * 60;
|
||||
const days = hours * 24;
|
||||
timer = setInterval(updateTime, seconds);
|
||||
function updateTime() {
|
||||
if (dayEl) {
|
||||
let now = new Date().getTime();
|
||||
const difference = end - now;
|
||||
|
||||
if (difference < 0) {
|
||||
if (timer) clearInterval(timer);
|
||||
cd.classList.add("hide");
|
||||
return;
|
||||
}
|
||||
|
||||
dayEl.innerText = Math.floor(difference / days);
|
||||
hoursEl.innerText = Math.floor( (difference % days) / hours );
|
||||
minutesEl.innerText = Math.floor( (difference % hours) / minutes );
|
||||
secondsEl.innerText = Math.floor( (difference % minutes) / seconds );
|
||||
}
|
||||
}
|
||||
updateTime();
|
||||
}
|
||||
Reference in New Issue
Block a user