Skip to content

Commit 67ceb72

Browse files
committed
Circular Progress Bar Animation
1 parent 3692972 commit 67ceb72

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="style.css">
8+
<title>Progress Bar</title>
9+
</head>
10+
<body>
11+
<div class="card">
12+
<div class="percent" style="--clr:#F36B9E;--num:85">
13+
<div class="dot"></div>
14+
<svg>
15+
<circle cx="70" cy="70" r="70"> </circle>
16+
<circle cx="70" cy="70" r="70"> </circle>
17+
</svg>
18+
<div class="number">
19+
<h2 id="percentNum"></h2>
20+
</div>
21+
</div>
22+
</div>
23+
</body>
24+
<script>
25+
let counter = 0;
26+
const num = document.getElementById('percentNum');
27+
setInterval( () => {
28+
if( counter != 85){
29+
counter++;
30+
num.innerHTML = `${counter}<span>%</span>`
31+
}
32+
}, 2000/85)
33+
</script>
34+
</html>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');
2+
* {
3+
margin: 0;
4+
padding: 0;
5+
box-sizing: border-box;
6+
font-family: 'Roboto', sans-serif;
7+
}
8+
body {
9+
display: flex;
10+
justify-content: center;
11+
align-items: center;
12+
min-height: 100vh;
13+
background-color: #202231;
14+
}
15+
.card {
16+
position: relative;
17+
display: flex;
18+
justify-content: center;
19+
align-items: center;
20+
width: 220px;
21+
height: 220px;
22+
}
23+
.card .percent {
24+
position: relative;
25+
width: 150px;
26+
height: 150px;
27+
}
28+
.card .percent svg {
29+
position: relative;
30+
width: 150px;
31+
height: 150px;
32+
transform: rotate(270deg);
33+
}
34+
.card .percent svg circle {
35+
width: 100%;
36+
height: 100%;
37+
fill: transparent;
38+
stroke-width: 2;
39+
stroke: rgb(0, 0, 0);
40+
transform: translate(5px, 5px);
41+
}
42+
.card .percent svg circle:nth-child(2) {
43+
stroke: var(--clr);
44+
stroke-dasharray: 440;
45+
stroke-dashoffset: 440;
46+
animation: barFills 2s linear forwards;
47+
}
48+
.dot{
49+
position: absolute;
50+
inset: 5px;
51+
z-index: 100;
52+
animation: animateDot 2s linear forwards;
53+
}
54+
.dot::before{
55+
content: '';
56+
position: absolute;
57+
top: -5px;
58+
left: 50%;
59+
width: 10px;
60+
height: 10px;
61+
background: var(--clr);
62+
border-radius: 50%;
63+
transform: translateX(-50%);
64+
box-shadow: 0 0 10px var(--clr), 0 0 30px var(--clr);
65+
}
66+
67+
@keyframes animateDot {
68+
0%{
69+
transform: rotate(0deg);
70+
}
71+
100%{
72+
transform: rotate(calc(3.6deg * var(--num) ));
73+
}
74+
}
75+
@keyframes barFills {
76+
100%{
77+
stroke-dashoffset: 66; /* calc(440 - (440 * var(--num))/100);*/
78+
}
79+
}
80+
81+
.number{
82+
position: absolute;
83+
inset: 0;
84+
display: flex;
85+
justify-content: center;
86+
align-items: center;
87+
flex-direction: column;
88+
color: #fff;
89+
}
90+
.number h2{
91+
font-weight: 700;
92+
font-size: 2.5em;
93+
}
94+
.number h2 span{
95+
font-size: 0.5em;
96+
}

0 commit comments

Comments
 (0)