-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock-with-minhr.html
89 lines (78 loc) · 2.22 KB
/
clock-with-minhr.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.clock {
position: relative;
width: 600px;
height: 600px;
border-radius: 50%;
background-color: rgb(248, 232, 232);
border: 1px solid black;
}
.hand {
position: absolute;
left: 300px;
top: 300px;
}
.hand-sec {
position: absolute;
width: 2px;
height: 270px;
left: -1px;
top: -270px;
background-color: rgb(245, 52, 52);
}
.hand-min {
position: absolute;
width: 12px;
height: 220px;
left: -6px;
top: -220px;
background-color: rgb(52, 58, 245);
}
.hand-hr {
position: absolute;
width: 22px;
height: 160px;
left: -11px;
top: -160px;
background-color: rgb(36, 176, 55);
}
</style>
</head>
<body>
<div class="clock">
<div class="hand">
<div class="hand-hr"></div>
</div>
<div class="hand">
<div class="hand-min"></div>
</div>
<div class="hand">
<div class="hand-sec"></div>
</div>
</div>
<script>
const hands = document.querySelectorAll(".clock>.hand");
const hr_hand = hands[0];
const min_hand = hands[1];
const sec_hand = hands[2];
const runClock = () => {
const now = new Date();
const s = now.getSeconds();
const m = now.getMinutes();
const h = now.getHours();
sec_hand.style.transform = `rotate(${s * 6}deg)`;
min_hand.style.transform = `rotate(${m * 6}deg)`;
hr_hand.style.transform = `rotate(${h * 30}deg)`;
setTimeout(runClock, 1000);
};
runClock();
</script>
</body>
</html>