javascript - 使用 SVG Logo 中的动画半圆

标签 javascript html svg svg-animate

我想用 SVG 制作这个图形。我可以使用<animate>标签,我可以使用 javascript 操作 SVG 文档。如果可能的话,我更愿意在 SVG 中完成这一切。

enter image description here

最佳答案

这是一个更简单的示例:

<svg height="200" width="200" viewBox="0 0 144 144">
    <circle cx="72" cy="72" r="49" stroke-width="6" stroke="#F68524" fill="none"/>
    <circle cx="72" cy="72" r="49" 
        stroke-width="6" stroke="#838588" fill="none">
        <animate attributeName="stroke-dasharray" values="154 0;0 154" dur="1s" repeatCount="indefinite"/>
    </circle>
</svg>

用于 lines-dasharray 的正确值基于圆的周长,2 * π * r,我们想要其中的一半,因此将其除以2. 在示例中,计算结果约为 154。

参见jsfiddle .

更新: 如前所述,非常接近,但不完全相同。这是一个也可以设置颜色动画的版本:

<svg height="200" width="200" viewBox="0 0 144 144">
    <circle cx="72" cy="72" r="49" stroke-width="6" stroke="#F68524" fill="none">
        <animate attributeName="stroke" values="#838588;#F68524" 
                 dur="2s" calcMode="discrete" repeatCount="indefinite"/>
    </circle>
    <circle cx="72" cy="72" r="49" 
        stroke-width="6" stroke="#838588" fill="none">
        <animate attributeName="stroke-dasharray" values="154 0;0 154" 
                 dur="1s" repeatCount="indefinite"/>
        <animate attributeName="stroke" values="#F68524;#838588" 
                 dur="2s" calcMode="discrete" repeatCount="indefinite"/>
    </circle>
</svg>

参见jsfiddle .

关于javascript - 使用 SVG Logo 中的动画半圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22047172/

相关文章:

html - 元素未正确调整大小

canvas - Raphael js使用canvas还是svg?

javascript - uncaughtException 然后appendFile on error 这会导致问题吗? NodeJs

javascript - Rest API,在路由中哪里放置大量计算?

javascript - 独立显示和隐藏内容

html - 通过 URL 插入时,SVG 图标显示损坏的图像

javascript - Firefox 中半透明矩形的 SVG 网格

javascript - 如何更改输入字段的插入光标的外观?

javascript - 将鼠标悬停在另一个元素上时显示一个元素

css - 3 个并排的 div,带标题的全高 (210x110x*)