【问题标题】:SVG: animateMotion with animated pathSVG:带有动画路径的 animateMotion
【发布时间】:2014-03-20 20:34:31
【问题描述】:

this fiddle 中有 2 条动画路径,curve0

<path id="curve0" stroke="black" fill="inherit" stroke-width="3" 
    fill-opacity=".5"
    d="M 0,100 
        C  50,100  50,50, 100,50 C 150,50 150,100 200,100
        C 300,100 200,50, 300,50 C 400,50 300,100 400,100">
    <animate attributeName="d"  dur="5s" 
        values="M 0,100 
        C  50,100  50,50, 100,50 C 150,50 150,150 200,150
        C 250,150 250,50, 300,50 C 350,50 350,100 400,100;

        M 0,100 
        C  50,100  50,150, 100,150 C 150,150 150, 50 200, 50
        C 250, 50 250,150, 300,150 C 350,150 350,100 400,100;

        M 0,100 
        C  50,100  50,50, 100,50 C 150,50 150,150 200,150
        C 250,150 250,50, 300,50 C 350,50 350,100 400,100" 
    repeatCount="indefinite"/>
</path>

曲线1

<path id="curve1" stroke="black" fill="yellowgreen" stroke-width="3" fill-opacity=".5" >
    <animate attributeName="d"  dur="3s" 
        values="M 100,0  0,100   70,50   130,150  200,100  z;
                M 100,0  0,100   70,150  130, 50  200,100  z;
                M 100,0  0,100   70,50   130,150  200,100  z" 
        repeatCount="indefinite"/>
</path> 

您可以看到椭圆与 curve0 一起很好地移动,但是如果您将第 36 行和第 46 行的 curve0 更改为 curve1,椭圆将停止移动。

为什么 curve1 不起作用,规范中的哪个位置 animateMotion 使用一种动画路径而不是另一种?

【问题讨论】:

    标签: animation svg


    【解决方案1】:

    它可以工作,但是您需要将 元素也更改为指向 curve1,而不仅仅是 元素(用于绘制曲线)。

    <animateMotion dur="5s" rotate="auto" repeatCount="indefinite">
      <mpath xlink:href="#curve1"/>
    </animateMotion>
    

    fiddle

    【讨论】:

    • 我在最新版本的 Chrome、Safari、Firefox 中尝试了小提琴,只有在 Firefox 中才有效。
    • FWIW 它在 Opera 12 (Presto) 中也运行良好。看起来像 webkit/chrome 中的一个错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-25
    • 2022-01-14
    • 2014-09-30
    • 1970-01-01
    • 2018-06-18
    • 2016-02-14
    • 2016-01-06
    相关资源
    最近更新 更多