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