Skip to content

Commit d20bd77

Browse files
committed
smooth clock version-1
0 parents  commit d20bd77

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

index.html

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Analog Clock</title>
8+
<link rel="stylesheet" href="style.css">
9+
</head>
10+
11+
<body>
12+
13+
<div class="container">
14+
<div class="clock">
15+
16+
<div class="hand animate" style="--clr:#23b89f; --h: 45px; animation-duration: 43200s;" id="hourhand"><i></i></div>
17+
<div class="hand animate" style="--clr:#49dce7; --h: 75px; animation-duration: 3600s" id="minutehand"><i></i></div>
18+
<div class="hand animate" style="--clr:#e04a4a; --h: 105px; animation-duration: 60s" id="secondhand"><i></i></div>
19+
20+
<span style="--i:1"><b>1</b></span>
21+
<span style="--i:2"><b>2</b></span>
22+
<span style="--i:3"><b>3</b></span>
23+
<span style="--i:4"><b>4</b></span>
24+
<span style="--i:5"><b>5</b></span>
25+
<span style="--i:6"><b>6</b></span>
26+
<span style="--i:7"><b>7</b></span>
27+
<span style="--i:8"><b>8</b></span>
28+
<span style="--i:9"><b>9</b></span>
29+
<span style="--i:10"><b>10</b></span>
30+
<span style="--i:11"><b>11</b></span>
31+
<span style="--i:12"><b>12</b></span>
32+
</div>
33+
</div>
34+
35+
36+
<script src="script.js"></script>
37+
</body>
38+
39+
</html>

script.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// using animation instead of rotation
2+
3+
const secondsHand = document.querySelector('#secondhand');
4+
const minutesHand = document.querySelector('#minutehand');
5+
const hoursHand = document.querySelector('#hourhand');
6+
const now = new Date();
7+
8+
function moveHands() {
9+
const secs = now.getSeconds();
10+
const mins = now.getMinutes() * 60;
11+
const hours = now.getHours() * 3600;
12+
13+
secondsHand.style.animationDelay = '-' + secs + 's';
14+
minutesHand.style.animationDelay = '-' + mins + 's';
15+
hoursHand.style.animationDelay = '-' + hours + 's';
16+
}
17+
18+
moveHands();

style.css

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');
2+
3+
*{
4+
margin: 0;
5+
padding: 0;
6+
box-sizing: border-box;
7+
font-family: poppins, sans-serif;
8+
color: #ffffff;
9+
}
10+
11+
body{
12+
background-color: rgba(0,0,0,0.8);
13+
display: flex;
14+
justify-content: center;
15+
align-items: center;
16+
min-height: 100vh;
17+
18+
}
19+
20+
.container{
21+
position: relative;
22+
}
23+
24+
.clock{
25+
display: flex;
26+
justify-content: center;
27+
align-items: center;
28+
width: 300px;
29+
height: 300px;
30+
border-radius: 50%;
31+
background-color: rgba(0,0,0,0.5);
32+
border: 2px solid rgba(255,255,255,0.3);
33+
box-shadow: 0 0 20px 0px rgba(255,255,255,0.3);
34+
}
35+
36+
.clock span{
37+
position: absolute;
38+
transform: rotate( calc( 30deg * var(--i)) );
39+
inset: 12px;
40+
text-align: center;
41+
padding: 5px;
42+
}
43+
44+
.clock span b{
45+
transform: rotate(calc(-30deg * var(--i)));
46+
display: inline-block;
47+
}
48+
49+
.clock::before{
50+
content: '';
51+
position: absolute;
52+
width: 8px;
53+
height: 8px;
54+
border-radius: 50%;
55+
background-color: #ffffff;
56+
z-index: 2;
57+
}
58+
59+
.hand{
60+
position: absolute;
61+
display: flex;
62+
justify-content: center;
63+
align-items: flex-end;
64+
65+
}
66+
67+
.hand i{
68+
position: absolute;
69+
width: 5px;
70+
height: var(--h);
71+
border-radius: 10px;
72+
background-color: var(--clr);
73+
74+
}
75+
76+
.animate{
77+
animation-name: smooth-rotation;
78+
animation-iteration-count: infinite;
79+
animation-timing-function: linear;
80+
}
81+
82+
@keyframes smooth-rotation {
83+
from{
84+
transform: rotate(0deg);
85+
}
86+
87+
to{
88+
transform: rotate(360deg);
89+
}
90+
}

0 commit comments

Comments
 (0)