如何在中风 - 戴式和中风挡群圆圈上实现动画?

发布于 2025-02-03 19:52:57 字数 680 浏览 3 评论 0原文

我尝试使用中风线制作Piechart,但是行不通。这个想法是Piechart将是从0到50行的动画。

#circle{
  stroke-dasharray: 50 100;
  stroke-dashoffset: 0;
  fill: none;
  stroke: black;
  stroke-width: 5px;
  transition: 0.3s;
  animation: progress 5s linear forwards;
  @keyframes progress  {
    from {
        stroke-dasharray: 0 100;
        stroke-dashoffset: 0;
    }
    to {
        stroke-dasharray: 50 100;
        stroke-dashoffset: 50;
    }
  }
}
<svg >
 <circle cx='24' cy='24' r='18' id="circle"/>
</svg>

I try to make piechart using stroke line, however isn't work. The idea is piechart will be animate from 0 to 50 line.

#circle{
  stroke-dasharray: 50 100;
  stroke-dashoffset: 0;
  fill: none;
  stroke: black;
  stroke-width: 5px;
  transition: 0.3s;
  animation: progress 5s linear forwards;
  @keyframes progress  {
    from {
        stroke-dasharray: 0 100;
        stroke-dashoffset: 0;
    }
    to {
        stroke-dasharray: 50 100;
        stroke-dashoffset: 50;
    }
  }
}
<svg >
 <circle cx='24' cy='24' r='18' id="circle"/>
</svg>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咋地 2025-02-10 19:52:57

关键帧处于规则不是该元素的CSS选择器的一部分。默认情况下,圆的路径从3点开始。可以使用属性路径长度控制圆路径的总长度。如果动画应顺时针顺时针进行,我认为通过在圆上设置转换/旋转属性而不是使用dasharray偏移来控制起点。

#circle {
  stroke-dasharray: 0 100;
  fill: none;
  stroke: black;
  stroke-width: 5px;
  animation: progress 5s linear forwards;
}

@keyframes progress {
  from {
    stroke-dasharray: 0 100;
  }
  to {
    stroke-dasharray: 100 100;
  }
}
<svg>
 <circle cx='24' cy='24' r='18' id="circle"
   pathLength="100" transform="rotate(-90 24 24)"/>
</svg>

The keyframes at-rule is not part of the CSS selector for the element. As default the path of the circle starts at 3 o'clock. The total length of the circle path can be controlled using the attribute pathLength. If the animation should go clockwise I think is is easier to control the starting point by setting the transform/rotate attribute on the circle instead of using the dasharray offset.

#circle {
  stroke-dasharray: 0 100;
  fill: none;
  stroke: black;
  stroke-width: 5px;
  animation: progress 5s linear forwards;
}

@keyframes progress {
  from {
    stroke-dasharray: 0 100;
  }
  to {
    stroke-dasharray: 100 100;
  }
}
<svg>
 <circle cx='24' cy='24' r='18' id="circle"
   pathLength="100" transform="rotate(-90 24 24)"/>
</svg>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文