-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
23 lines (17 loc) · 777 Bytes
/
script.js
File metadata and controls
23 lines (17 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const hourHand = document.querySelector(".hand.hours");
const minuteHand = document.querySelector(".hand.minutes");
const secondHand = document.querySelector(".hand.seconds");
const setRotation = (element, rotationPercentage) => {
element.style.setProperty("--rotation", rotationPercentage * 360);
}
const setClock = () => {
const currentDate = new Date();
const secondsPercentage = currentDate.getSeconds() / 60;
const minutesPercentage = (secondsPercentage + currentDate.getMinutes()) / 60;
const hoursPercentage = (minutesPercentage + currentDate.getHours()) / 12;
setRotation(secondHand, secondsPercentage);
setRotation(minuteHand, minutesPercentage);
setRotation(hourHand, hoursPercentage);
};
setClock();
setInterval(setClock, 1000);