-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
41 lines (33 loc) · 986 Bytes
/
Copy pathscript.js
File metadata and controls
41 lines (33 loc) · 986 Bytes
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
const $ = (selector) => {
return document.querySelector(selector);
};
const $hour = $('.hour');
const $min = $('.min');
const $sec = $('.sec');
const getTime = () => {
const now = new Date();
return {
hour: String(now.getHours())
.padStart(2, '0'),
min: String(now.getMinutes())
.padStart(2, '0'),
sec: String(now.getSeconds())
.padStart(2, '0'),
};
};
const setDigits = (section, digit) => {
const $tens = [...section.children[0].children];
const $ones = [...section.children[1].children];
$tens.forEach(($number) => $number.classList.remove('active'));
$tens[digit[0]].classList.add('active');
$ones.forEach(($number) => $number.classList.remove('active'));
$ones[digit[1]].classList.add('active');
};
const update = () => {
const Time = getTime();
setDigits($hour, Time.hour);
setDigits($min, Time.min);
setDigits($sec, Time.sec);
};
update();
setInterval(update, 1000);