更改动画对象

时间:2019-10-03 08:28:28

标签: javascript html svg

我有这样的svg动画:

<svg width="500" height="350" viewBox="0 0 500 350">
      <path id="motionPath" fill="none" stroke="#000000" stroke-miterlimit="10" d="M202.4,58.3c-13.8,0.1-33.3,0.4-44.8,9.2
    	c-14,10.7-26.2,29.2-31.9,45.6c-7.8,22.2-13.5,48-3.5,70.2c12.8,28.2,47.1,43.6,68.8,63.6c19.6,18.1,43.4,26.1,69.5,29.4
    	c21.7,2.7,43.6,3.3,65.4,4.7c19.4,1.3,33.9-7.7,51.2-15.3c24.4-10.7,38.2-44,40.9-68.9c1.8-16.7,3.4-34.9-10.3-46.5
    	c-9.5-8-22.6-8.1-33.2-14.1c-13.7-7.7-27.4-17.2-39.7-26.8c-5.4-4.2-10.4-8.8-15.8-12.9c-4.5-3.5-8.1-8.3-13.2-11
    	c-6.2-3.3-14.3-5.4-20.9-8.2c-5-2.1-9.5-5.2-14.3-7.6c-6.5-3.3-12.1-7.4-19.3-8.9c-6-1.2-12.4-1.3-18.6-1.5
    	C222.5,59,212.5,57.8,202.4,58.3"/>
      
      <circle id="circle" r="10" cx="0" cy="0" fill="tomato" />
       
      <animateMotion 
               xlink:href="#circle"
               dur="5s"
               begin="0s"
               fill="freeze"
               repeatCount="indefinite">
        <mpath xlink:href="#motionPath" />
      </animateMotion>
    </svg>

但是我有一些svg图像,而不是圆形的,我需要在动画的某个阶段将此图像更改为另一幅图像。

<svg width="50" height="35" viewBox="0 0 500 350">
<path id="motionPath1" fill="none" stroke="rgba(255, 255, 255, 0.3)" stroke-miterlimit="10" d="M 100 50 C 150 600 650 600 700 50 "/>

<foreignObject transform="scale(0.5), translate(-25, -25)" id="car1" width="160" height="160"
>
  <svg xmlns="http://www.w3.org/2000/svg"><path class="ytp-large-play-button-bg" d="M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.55 C3.97,2.33,2.27,4.81,1.48,7.74C0.06,13.05,0,24,0,24s0.06,10.95,1.48,16.26c0.78,2.93,2.49,5.41,5.42,6.19 C12.21,47.87,34,48,34,48s21.79-0.13,27.1-1.55c2.93-0.78,4.64-3.26,5.42-6.19C67.94,34.95,68,24,68,24S67.94,13.05,66.52,7.74z" fill="#f00" fill-opacity="1"></path><path d="M 45,24 27,14 27,34" fill="#fff"></path></svg>

</foreignObject>

<animateMotion xlink:href="#car1" dur="8s" begin="1.3s" fill="freeze" repeatCount="indefinite" rotate="auto-reverse">
  <mpath xlink:href="#motionPath1" />
</animateMotion>
</svg>

0 个答案:

没有答案