【发布时间】:2021-11-03 04:34:26
【问题描述】:
我正在构建一个 SVG Circle 进度表。
在下面的sn-p中。我显示仪表渲染完成 20%。问题是我需要仪表从顶部中心开始,而不是像现在的 90 度。如何让 SVG 圆圈进度表从圆圈的顶部/中心开始?
#svg circle {
stroke-dashoffset: 0;
transition: stroke-dashoffset 1s linear;
stroke: #311321;
stroke-width: 1em;
}
#svg #bar {
stroke: red ;
}
#cont {
display: block;
height: 200px;
width: 200px;
margin: 2em auto;
border-radius: 100%;
position: relative;
}
#cont:after {
position: absolute;
display: block;
height: 160px;
width: 160px;
left: 50%;
top: 50%;
content: attr(data-pct)"%";
margin-top: -80px;
margin-left: -80px;
border-radius: 100%;
line-height: 160px;
font-size: 2em;
}
<div id="cont" data-pct="20">
<svg id="svg" width="200" height="200" viewPort="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
<circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0" style="stroke-dashoffset: 452.389;"></circle>
</svg>
</div>
【问题讨论】:
-
我会将 2 个圆圈放在一个组中并旋转该组
<g transform="rotate(-90 100 100)"> -
另外 viewPort 也不会做任何事情,你的意思是 viewBox