-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
28 lines (22 loc) · 875 Bytes
/
script.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
let digitalElement = document.querySelector('.digital');
let sElement = document.querySelector('.p_s');
let mElement = document.querySelector('.p_m');
let hElement = document.querySelector('.p_h');
function updateClock() {
let now = new Date();
let hour = now.getHours();
let minute = now.getMinutes();
let second = now.getSeconds();
digitalElement.innerHTML = `${fixZero(hour)}:${fixZero(minute)}:${fixZero(second)}`;
let sDeg = ((360 / 60) * second) - 90;
let mDeg = ((360 / 60) * minute) - 90;
let hDeg = ((360 / 12) * hour) - 90;
sElement.style.transform = `rotate(${sDeg}deg)`;
mElement.style.transform = `rotate(${mDeg}deg)`;
hElement.style.transform = `rotate(${hDeg}deg)`;
}
function fixZero(time) {
return time < 10 ? `0${time}` : time;
}
setInterval(updateClock, 1000);
updateClock();