-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime.js
46 lines (34 loc) · 1.04 KB
/
time.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
console.clear();
const hour = document.getElementById("hour");
const minute = document.getElementById("minute");
const second = document.getElementById("second");
const progress = document.querySelector(".progress-bar");
const toasts = document.getElementsByClassName("toast");
var interval;
[...toasts].forEach(toast => {
toast.addEventListener("click", hideToast);
});
function hideToast(e) {
const target = e.target;
if (target.tagName.toUpperCase() === "SPAN") {
target.parentNode.classList.remove("show");
}
}
function getCurrentTime() {
const d = new Date();
let h = d.getHours();
let min = d.getMinutes();
let sec = d.getSeconds();
h = h < 10 ? "0" + h : h;
min = min < 10 ? "0" + min : min;
sec = sec < 10 ? "0" + sec : sec;
hour.textContent = h;
minute.textContent = min;
second.textContent = sec;
}
function clearClass(className) {
for (let i = 0; i < toasts.length; i++) {
toasts[i].classList.remove(className);
}
}
interval = setInterval(getCurrentTime, 1000);