-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
25 lines (21 loc) · 880 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
setInterval(setClock, 1000);
const hourHand = document.querySelector("[data-hour-hand]");
const minuteHand = document.querySelector("[data-minute-hand]");
const secondHand = document.querySelector("[data-second-hand]");
const tick = document.querySelector("audio");
function setClock() {
const currentDate = new Date();
const secondsRatio = currentDate.getSeconds() / 60;
const minutesRatio = (secondsRatio + currentDate.getMinutes()) / 60;
const hoursRatio = (minutesRatio + currentDate.getHours()) / 12;
setRotation(secondHand, secondsRatio);
setRotation(minuteHand, minutesRatio);
setRotation(hourHand, hoursRatio);
tick.play();
}
function setRotation(element, rotationRatio) {
element.style.setProperty("--rotation", rotationRatio * 360);
}
setClock();
var d = new Date();
document.getElementById("day").innerHTML = d.getDate();