-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
58 lines (51 loc) · 1.88 KB
/
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
let angle = 30;
for(let i=1;i<=11;i++){
let ele = document.querySelector(`.number${i}`);
ele.style.setProperty("--rotation" , `${angle}deg`);
angle+=30;
}
setInterval(setClock , 1);
const hourHand = document.querySelector(".hour-hand");
const minuteHand = document.querySelector(".minute-hand");
const secondHand = document.querySelector(".second-hand");
const dateForMili = new Date();
const exactMiliSecond = dateForMili.getMilliseconds();
let miliseconds = exactMiliSecond;
function setClock(){
if(miliseconds < 60000){
miliseconds++;
}
else{
miliseconds = 0;
}
let miliSecondratio = miliseconds / 60000;
let miliSecondRotation = miliSecondratio * 360;
let currentDate = new Date();
let secondratio = (currentDate.getSeconds()) / 60;
let secondRotation = secondratio*360;
let minuteratio = (secondratio + currentDate.getMinutes())/60;
let minuteRotation = (minuteratio)*360;
let hourratio = (minuteratio + currentDate.getHours())/12;
let hourRotation = hourratio*360;
// let minuteRotation = (currentDate.getSeconds())
// secondHand.style.setProperty("--rotation" , `${miliSecondRotation}deg`);
// secondHand.style.setProperty("transform" , `rotate(${secondRotation}deg)`);
rotateHand(secondHand , miliSecondRotation);
rotateHand(minuteHand , minuteRotation);
rotateHand(hourHand , hourRotation);
}
function rotateHand(hand , rotation){
hand.style.setProperty("--rotation" , `${rotation}deg`);
hand.style.setProperty("transform" , `rotate(${rotation}deg)`);
}
setClock();
for(let i=4;i<=8;i++){
let element = document.querySelector(`.number${i} div`);
element.style.setProperty("transform" , `rotate(180deg)`);
}
for(let i=3;i<=9;i+=6){
if(i==9){
let element = document.querySelector(`.number${i} div`);
element.style.setProperty("transform" , `rotate(90deg)`);
}
}