-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
21 lines (16 loc) · 705 Bytes
/
script.js
File metadata and controls
21 lines (16 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
setInterval(setClock, 1000)
const hourHand = document.querySelector('[date-hour-hand]')
const minuteHand = document.querySelector('[date-minute-hand]')
const secondHand = document.querySelector('[date-second-hand]')
function setClock() {
const currentDate = new Date()
const secondRatio = currentDate.getSeconds() / 60
const minuteRatio = (secondRatio + currentDate.getMinutes()) / 60
const hoursRatio = (minuteRatio + currentDate.getHours()) / 12
setRotation(secondHand, secondRatio)
setRotation(minuteHand, minuteRatio)
setRotation(hourHand, hoursRatio)
}
function setRotation(element, rotationRatio) {
element.style.setProperty('--rotation', rotationRatio * 360)
}