CSS100Day(22)-使用svg实现圆形进度条

850 字
4 分钟
CSS100Day(22)-使用svg实现圆形进度条

设计简介#

关键点如下

  1. 知识点1:还是通过 fill: none; 以及 stroke-dasharray 来实现

  2. 知识点2:还有个stroke圆形边缘使用 stroke-linecap: round 来实现

  3. 知识点3:使用 animation 来做进度条增加动画

效果展示#

YOUR DAILY
PROGRESS
2758
kcal
8563
steps
6,2
km

实现代码和步骤#

HTML部分#

<div class="frame">
<div class="title">
<div class="small">YOUR DAILY</div>
PROGRESS
</div>
<div class="big-circle">
<div class="text">
2758
<div class="small">kcal</div>
</div>
<svg>
<circle class="bg" cx="57" cy="57" r="52"></circle>
<circle class="progress" cx="57" cy="57" r="52"></circle>
</svg>
</div>
<div class="small-circle-group">
<div class="small-circle">
<div class="text">
8563
<div class="small">steps</div>
</div>
<svg>
<circle class="bg" cx="40" cy="40" r="37"></circle>
<circle class="progress one" cx="40" cy="40" r="37"></circle>
</svg>
</div>
<div class="small-circle">
<div class="text">
6,2
<div class="small">km</div>
</div>
<svg>
<circle class="bg" cx="40" cy="40" r="37"></circle>
<circle class="progress two" cx="40" cy="40" r="37"></circle>
</svg>
</div>
</div>
</div>

CSS部分#

:root {
--bg: #28404e;
--stroke-bg: #1b2a33;
--big-stroke: #27e1ae;
--small-stroke: #5ce1ec;
}
.frame {
width: 400px;
height: 400px;
box-shadow: 1px 2px 10px 0 rgba(0, 0, 0, 0.3);
background: var(--bg);
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
padding-top: 50px;
padding-bottom: 60px;
box-sizing: border-box;
overflow: hidden;
}
.title {
font-weight: 700;
font-size: 24px;
text-transform: uppercase;
text-align: center;
line-height: 22px;
.small {
font-weight: 300;
font-size: 16px;
}
}
.big-circle {
width: 114px;
height: 114px;
text-align: center;
position: relative;
margin: 30px auto 25px auto;
.text {
position: absolute;
font-size: 24px;
font-weight: 600;
text-align: center;
width: 100%;
top: 37px;
line-height: 22px;
.small {
font-size: 14px;
font-weight: 300;
color: #648192;
}
}
svg {
width: 114px;
height: 114px;
.bg {
stroke: var(--stroke-bg);
fill: none;
stroke-width: 10px;
}
.progress {
stroke: var(--big-stroke);
stroke-linecap: round;
fill: none;
stroke-width: 10px;
stroke-dasharray: calc(2 * 52 * 3.14px);
stroke-dashoffset: 60px;
transform-origin: 50% 50%;
transform: rotate(-90deg);
animation: big 1.5s ease-out;
}
}
}
.small-circle-group {
margin: 0 auto;
width: 400px;
height: 80px;
display: flex;
justify-content: center;
gap: 40px;
.small-circle {
width: 80px;
height: 80px;
position: relative;
svg {
width: 80px;
height: 80px;
}
.bg {
fill: none;
stroke-width: 6px;
stroke: #1b2a33;
}
.text {
position: absolute;
font-size: 17px;
font-weight: 600;
width: 100%;
text-align: center;
top: 26px;
line-height: 16px;
.small {
font-size: 12px;
color: #648192;
}
}
.progress {
fill: none;
stroke-width: 6px;
stroke-linecap: round;
stroke: var(--small-stroke);
stroke-dasharray: calc(2 * 37 * 3.14px);
transform-origin: 50% 50%;
transform: rotate(-90deg);
&.one {
stroke-dashoffset: 80px;
animation: one 1.5s ease-out;
}
&.two {
stroke-dashoffset: 140px;
animation: two 1.5s ease-out;
}
}
}
}
@keyframes big {
from {
stroke-dashoffset: calc(2 * 52 * 3.14px);
}
to {
stroke-dashoffset: 60px;
}
}
@keyframes one {
from {
stroke-dashoffset: calc(2 * 37 * 3.14px);
}
to {
stroke-dashoffset: 80px;
}
}
@keyframes two {
from {
stroke-dashoffset: calc(2 * 37 * 3.14px);
}
to {
stroke-dashoffset: 140px;
}
}
分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接

评论区

图片
犟哟
Hello, I'm Juyial.
公告
欢迎来到我的博客,在这里可以一起进步,一起学习!2026年起航!
分类
站点统计
文章
20
分类
1
标签
3
总字数
37,015
运行时长
0
最后活动
0 天前

目录