-
Notifications
You must be signed in to change notification settings - Fork 2
/
clock.html
154 lines (136 loc) · 3.31 KB
/
clock.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Responsive Clock</title>
<style type="text/css">
body {
background-color: black;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 90vh;
}
#container {
display: flex;
flex-direction: column;
align-items: center;
width: 90vw;
max-width: 90vh; /* Ensures the clock stays circular */
}
#clock-rim {
position: relative;
width: 100%;
padding-top: 100%; /* Keeps the clock a square */
background: black;
border-radius: 50%;
overflow: hidden;
}
#clock-base {
position: absolute;
top: 5%;
left: 5%;
width: 90%;
height: 90%;
background: black;
border-radius: 50%;
}
/* Clock hands */
#second, #minute, #hour {
position: absolute;
top: 50%;
left: 50%;
transform-origin: 50% 100%;
}
#second {
width: 1%;
height: 45%;
background: grey;
transform: translate(-50%, -100%);
}
#minute {
width: 1.5%;
height: 40%;
background: white;
transform: translate(-50%, -100%);
}
#hour {
width: 2%;
height: 30%;
background: white;
transform: translate(-50%, -100%);
}
#center {
position: absolute;
top: 50%;
left: 50%;
width: 3%;
aspect-ratio: 1;
background: grey;
border-radius: 50%;
transform: translate(-50%, -50%);
}
/* Notches */
.notch, .thin {
position: absolute;
top: 5%;
left: 5%;
width: 90%;
height: 90%;
transform-origin: 50% 50%;
}
.notch::before, .thin::before {
content: "";
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
width: 1%; /* Thinner notches */
border-radius: 2px;
}
.notch::before {
height: 4%;
background: white;
}
.thin::before {
height: 2%;
background: grey;
}
</style>
<script type="text/javascript">
window.onload = function () {
setInterval(() => {
const date = new Date();
const S = date.getSeconds();
const M = date.getMinutes();
const H = date.getHours();
// Update the clock hands
document.getElementById("second").style.transform = `translate(-50%, -100%) rotate(${S * 6}deg)`;
document.getElementById("minute").style.transform = `translate(-50%, -100%) rotate(${M * 6}deg)`;
document.getElementById("hour").style.transform = `translate(-50%, -100%) rotate(${H * 30 + M * 0.5}deg)`;
}, 1000);
// Generate clock notches
const container = document.getElementById("clock-base");
for (let i = 0; i < 60; i++) {
let div = document.createElement("div");
div.className = i % 5 === 0 ? "notch" : "thin";
div.style.transform = `rotate(${i * 6}deg)`;
container.appendChild(div);
}
};
</script>
</head>
<body>
<div id="container">
<div id="clock-rim">
<div id="clock-base">
<div id="hour"></div>
<div id="minute"></div>
<div id="second"></div>
<div id="center"></div>
</div>
</div>
</div>
</body>
</html>