【发布时间】:2021-04-08 02:45:38
【问题描述】:
我正在尝试寻找一种方法来实现没有动画的简单进度圈(静态)。我发现的示例具有非常不同的百分比偏移量,如下例所示。如何使我的进度圈以这样的方式进行,如果我提供 50% 的偏移量,那么它正好是 50%(半填充)?
.u-absoluteCenter {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
}
.u-flexCenter {
display: flex;
align-items: center;
justify-content: center;
}
.u-offscreen {
position: absolute;
left: -999em;
}
.demo {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
display: flex;
align-items: center;
justify-content: center;
}
.progress {
transform: rotate(-90deg);
}
.progress__value {
stroke-dasharray: 0;
stroke-dashoffset: 0;
}
@-webkit-keyframes progress {
from {
stroke-dashoffset: 339.292;
}
to {
stroke-dashoffset: 0;
}
}
@keyframes progress {
from {
stroke-dashoffset: 339.292;
}
to {
stroke-dashoffset: 0;
}
}
<svg width="120" height="120" viewBox="0 0 120 120">
<circle cx="60" cy="60" r="54" fill="none" stroke="#e6e6e6" stroke-width="12" />
<circle cx="60" cy="60" r="54" fill="none" stroke="#f77a52" stroke-width="12"
stroke-dasharray="339.292" stroke-dashoffset="339.292" />
</svg>
【问题讨论】:
-
对于 25% 尝试
stroke-dasharray="84.823 254.469",其中笔划 84.823 代表路径长度 (339.292) 的 25%,间隙 (254.469) 代表 75%。