-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.js
41 lines (33 loc) · 1.2 KB
/
clock.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
29
30
31
32
33
34
35
36
37
38
39
40
41
// console.log("Program started");
setInterval(setClock, 1000)
const secHand = document.querySelector('.second-hand')
const minHand = document.querySelector('.minute-hand')
const hourHand = document.querySelector('.hour-hand')
function setClock() {
const currentDate = new Date();
const secondsRatio = currentDate.getSeconds()/60
const minutesRatio = (currentDate.getMinutes() + secondsRatio)/60
// const hoursRatio = currentDate.getHours()/60
const hoursRatio = (checkHours(currentDate.getHours())+minutesRatio)/12
// console.log(hoursRatio,minutesRatio,secondsRatio);
// console.log(currentDate.getHours(),currentDate.getMinutes(),currentDate.getSeconds());
// console.log();
// console.log(secondsRatio, currentDate.getSeconds());
setRotation(secHand, secondsRatio)
setRotation(minHand, minutesRatio)
setRotation(hourHand, hoursRatio)
}
function setRotation(element, ratio) {
element.style.setProperty('--rotation',ratio * 360 )
}
function checkHours(hour) {
if (hour>12) {
hour -= 12
// console.log(hour);
return hour
}else{
// console.log(hour);
return hour
}
}
setClock();