[英]With a SVG circle, how to position the starting point?
I'm working to create an SVG circle progress indicator in react... Here is my output: 我正在努力在react中创建SVG圈子进度指示器...这是我的输出:
The problem is I need the red stroke to start at the top, not at the current 90% angle... Is there some CSS I can add to reposition the red stroke to start at the top? 问题是我需要红色笔触从顶部开始,而不是从当前的90%角度开始...是否可以添加一些CSS以重新定位红色笔触从顶部开始?
FYI, I'm using the following component in react to render this HTML: https://github.com/wmartins/react-circular-progress/blob/gh-pages/src/js/components/CircularProgress.jsx.js 仅供参考,我在反应中使用以下组件来呈现此HTML: https : //github.com/wmartins/react-circular-progress/blob/gh-pages/src/js/components/CircularProgress.jsx.js
codepen source below 下面的codepen源
html HTML
<svg class="CircularProgress" width="50" height="50" viewBox="0 0 50 50">
<circle class="CircularProgress-Bg" cx="25" cy="25" r="24" stroke-width="2px"></circle>
<circle class="CircularProgress-Fg" cx="25" cy="25" r="24" stroke-width="2px" style="stroke-dasharray: 150.796; stroke-dashoffset: 125.161;"></circle>
<text class="CircularProgress-Text" x="25" y="25" dy=".4em" text-anchor="middle">17%</text>
</svg>
css CSS
.CircularProgress-Bg,
.CircularProgress-Fg {
fill: none;
}
.CircularProgress-Bg {
stroke: #CCC;
}
.CircularProgress-Fg {
transition: stroke-dashoffset .5s ease-in-out;
stroke: red;
}
.CircularProgress-Text {
font-size: 15px;
font-weight: 600;
fill: rgba(255,255,255,0.9);
transform: translate(0 50%);
}
You could use transform
, add transform="rotate(-90 25 25)"
and it will start at the top 您可以使用
transform
,添加transform="rotate(-90 25 25)"
,它将从顶部开始
.CircularProgress-Bg, .CircularProgress-Fg { fill: none; } .CircularProgress-Bg { stroke: #CCC; } .CircularProgress-Fg { transition: stroke-dashoffset .5s ease-in-out; stroke: red; } .CircularProgress-Text { font-size: 15px; font-weight: 600; fill: rgba(255,255,255,0.9); transform: translate(0 50%); }
<svg class="CircularProgress" width="50" height="50" viewBox="0 0 50 50"> <circle class="CircularProgress-Bg" cx="25" cy="25" r="24" stroke-width="2px"></circle> <circle transform="rotate(-90 25 25)" class="CircularProgress-Fg" cx="25" cy="25" r="24" stroke-width="2px" style="stroke-startOffest: 50%;stroke-dasharray: 150.796; stroke-dashoffset: 125.161;"></circle> <text class="CircularProgress-Text" x="25" y="25" dy=".4em" text-anchor="middle">17%</text> </svg>
If to use CSS, you can rotate the svg
element instead of the circle
(which might or might not be possible based on its shape) 如果要使用CSS,则可以旋转
svg
元素而不是circle
(根据其形状,可能会或可能不会)
.CircularProgress { transform: rotate(-90deg); } .CircularProgress-Bg, .CircularProgress-Fg { fill: none; } .CircularProgress-Bg { stroke: #CCC; } .CircularProgress-Fg { transition: stroke-dashoffset .5s ease-in-out; stroke: red; } .CircularProgress-Text { font-size: 15px; font-weight: 600; fill: rgba(255,255,255,0.9); transform: translate(0, 50%); }
<svg class="CircularProgress" width="50" height="50" viewBox="0 0 50 50"> <circle class="CircularProgress-Bg" cx="25" cy="25" r="24" stroke-width="2px"></circle> <circle class="CircularProgress-Fg" cx="25" cy="25" r="24" stroke-width="2px" style="stroke-dasharray: 150.796; stroke-dashoffset: 125.161;"></circle> <text class="CircularProgress-Text" x="25" y="25" dy=".4em" text-anchor="middle">17%</text> </svg>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.