【问题标题】:Can i create a circle that follow an existing line in svg?我可以创建一个遵循 svg 中现有线的圆圈吗?
【发布时间】:2021-01-22 17:27:48
【问题描述】:

正如标题所暗示的,我正在尝试在 svg 中创建一个动画,其中包含一个遵循不规则路径的点/圆。我正在使用animateTransform,例如:

<animateTransform attributeName="transform"
                  attributeType="XML"
                  type="translate"
                  from="0 60 70"
                  to="360 60 70"
                  dur="10s"
                  repeatCount="definite"/>

我可以实现这个方法(在 svg 中)让圆圈跟随路径,还是我必须使用 javascript? 如果我可以在 svg 中做到这一点,你能给我一个带有解释的基本示例吗?

【问题讨论】:

    标签: svg


    【解决方案1】:

    您可以使用&lt;animateMotion&gt; 元素。

    例子改编自MDN:

    <svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">
      <path id="path" fill="none" stroke="lightgrey"
        d="M20,50 C20,-50 180,150 180,50 C180-50 20,150 20,50 z" />
    
      <circle r="5" fill="red">
        <animateMotion dur="10s" repeatCount="indefinite">
          <mpath xlink:href="#path"/>
        </animateMotion>
      </circle>
    </svg>

    【讨论】:

    • 这是在进行深入研究之前询问的坏习惯。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 2018-12-15
    • 2014-12-07
    • 1970-01-01
    相关资源
    最近更新 更多