- 将圆的坐标放在中心只能通过选择来获得 transform='rotate(-90 60 60)'
- 如何在不选择的情况下立即将圆的坐标放在中心?
<svg id="svg1" xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="200" height="200" viewBox="0 0 120 120" >
<!-- Фон серого цвета -->
<rect x='0' y='0' width='100%' height='100%' fill='grey'/>
<circle r='50' cx='60' cy='60' fill='none' stroke='white' stroke-width='8' transform='rotate(-90 60 60)' />
<circle r='50' cx='60' cy='60' fill='none' transform='rotate(-90 60 60)' stroke-dashoffset='314' stroke-dasharray='314' stroke='dodgerblue' stroke-width='8'>
<animate
attributeName='stroke-dashoffset'
dur='4s'
begin='svg1.click'
values='314; 0'
/>
</circle>
<text x="50%" y="50%" text-anchor='middle' font-size='20' fill="">click</text>
</svg>
要确定大小,使用 JS getBBox()方法
MDN 网络文档
换句话说,我们可以获得描述圆的矩形左上角的 (x,y) 坐标,在您的示例中
,该矩形的宽度和高度为
width。height计算圆心坐标
下面是一个完整的例子