kcal
CSS100Day(22)-使用svg实现圆形进度条
850 字
4 分钟
CSS100Day(22)-使用svg实现圆形进度条
设计简介
关键点如下
-
知识点1:还是通过
fill: none;以及stroke-dasharray来实现 -
知识点2:还有个stroke圆形边缘使用
stroke-linecap: round来实现 -
知识点3:使用
animation来做进度条增加动画
效果展示
YOUR DAILY
PROGRESS
2758
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; }}分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接
相关文章
推荐筛选
1
CSS100Day(17)-svg实现彭罗斯三角
设计灵感 三个svg实现彭罗斯三角
2
CSS100Day(21)-利用svg线段实现吃小球动画
设计灵感 利用svg线段实现吃小球动画
3
CSS100Day(18)-3D实现弹性元素
设计灵感 3D实现弹性元素
4
CSS100Day(10)-SVG旋转动画
设计灵感 巧妙应用SVG的
5
CSS100Day(19)-纯css实现滑动radio轮播图
设计灵感 纯css使用translateX实现轮播图
随机文章
随机推荐