-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigital Clock.html
205 lines (178 loc) · 5.3 KB
/
Digital 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!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>Digital Clock</title>
</head>
<style>
* {
margin: 0%;
padding: 0%;
box-sizing: border-box;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}
body {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background-size: 300% 300%;
background-image: linear-gradient( -45deg, rgba(59, 173, 227, 1) 0%, rgba(87, 111, 230, 1) 25%, rgba(152, 68, 183, 1) 51%, rgba(255, 53, 127, 1) 100%);
animation: AnimateBG 20s ease infinite;
}
@keyframes AnimateBG {
0% {
background-position: 0% 50%
}
50% {
background-position: 100% 50%
}
100% {
background-position: 0% 50%
}
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #2f363e;
}
#time {
display: flex;
gap: 40px;
color: white;
}
#time .circle {
position: relative;
width: 150px;
height: 150px;
display: flex;
justify-content: center;
align-items: center;
}
#time .circle svg {
position: relative;
width: 150px;
height: 150px;
transform: rotate(270deg);
}
#time .circle svg circle {
width: 100%;
height: 100%;
fill: transparent;
stroke: #191919;
stroke-width: 4;
transform: translate(5px, 5px);
}
#time .circle svg circle:nth-child(2) {
stroke: var(--clr);
stroke-dasharray: 440;
}
#time div {
position: absolute;
text-align: center;
font-weight: 500;
font-size: 1.5em;
}
#time div span {
position: absolute;
font-size: 0.35em;
font-weight: 300;
letter-spacing: 0.1em;
text-decoration: uppercase;
transform: translateX(-50%) translateY(-1px);
}
#time .ap {
position: relative;
font: 1em;
transform: translateX(-20px);
}
.dots {
position: absolute;
width: 100%;
height: 100%;
z-index: 10;
display: flex;
justify-content: center;
}
.dots::before {
content: "";
position: absolute;
top: -3px;
width: 15px;
height: 15px;
background: var(--clr);
border-radius: 50%;
box-shadow: 0 0 20px var(--clr), 0 0 60px var(--clrs)
}
</style>
<body>
<div id="time">
<div class="circle" style="--clr:#ff2972">
<div class="dots hr_dot"></div>
<svg>
<circle cx="70" cy="70" r="70"></circle>
<circle cx="70" cy="70" r="70" id="hh"></circle>
</svg>
<div id="hours">00</div>
</div>
<div class="circle" style="--clr:#fee800">
<div class="dots mm_dot"></div>
<svg>
<circle cx="70" cy="70" r="70"></circle>
<circle cx="70" cy="70" r="70" id="mm"></circle>
</svg>
<div id="minutes">00</div>
</div>
<div class="circle" style="--clr:#04fc43">
<div class="dots sec_dot"></div>
<svg>
<circle cx="70" cy="70" r="70"></circle>
<circle cx="70" cy="70" r="70" id="ss"></circle>
</svg>
<div id="seconds">00</div>
</div>
<div class="ap">
<div id="ampm">AM</div>
</div>
</div>
</body>
</html>
<script>
setInterval(() => {
let hours = document.getElementById("hours")
let minutes = document.getElementById("minutes")
let seconds = document.getElementById("seconds")
let ampm = document.getElementById("ampm")
let hh = document.getElementById("hh")
let mm = document.getElementById("mm")
let ss = document.getElementById("ss")
let hr_dot = document.querySelector(".hr_dot");
let min_dot = document.querySelector(".mm_dot");
let sec_dot = document.querySelector(".sec_dot");
let h = new Date().getHours();
let m = new Date().getMinutes();
let s = new Date().getSeconds();
h = (h < 10) ? "0" + h : h;
m = (m < 10) ? "0" + m : m;
s = (s < 10) ? "0" + s : s;
if (h > 12) {
h = h - 12;
}
let am = h >= 12 ? "AM" : "PM"
hours.innerHTML = h + "<br><span>Hours</span>";
minutes.innerHTML = m + "<br><span>Minutes</span>";
seconds.innerHTML = s + "<br><span>Seconds</span>";
ampm.innerHTML = am;
hh.style.strokeDashoffset = 440 - (440 * h) / 12;
mm.style.strokeDashoffset = 440 - (440 * m) / 60;
ss.style.strokeDashoffset = 440 - (440 * s) / 60;
hr_dot.style.transform = `rotate(${h*30}deg)`;
min_dot.style.transform = `rotate(${m*6}deg)`;
sec_dot.style.transform = `rotate(${s*6}deg)`;
})
</script>