animateTransform无法正常工作

时间:2016-03-11 22:11:22

标签: html css svg

我正在尝试让SVG组遵循SVG路径并对组进行动画处理。我试图使用animateTransform进行#moon变换,但似乎没有任何效果。

有人能发现问题吗?

<svg width="100%" height="100%" viewBox="0 0 570 594" preserveAspectRatio="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="padding: 0 10px 0 18px;fill-rule:evenodd;clip-rule:evenodd;stroke-miterlimit:10;">
    <path id="orbit" d="M146.719,183.637l-18.408,-7.796l-13.233,-6.252l-12.327,-6.302l-18.44,-9.379l-12.42,-11.695l-16.36,-10.421l-15.546,-10.511l-12.326,-12.281l-14.415,-14.728l-8.426,-16.45l-4.168,-14.276l2.084,-14.272l6.297,-11.239l8.019,-10.103l12.013,-6.302l16.682,-8.426l16.356,-4.169l22.804,-4.217l27.474,-4.168l22.03,0l21.75,1.042l24.881,1.042l20.524,1.042l26.875,3.126l27.917,5.211l41.477,9.293l37.047,10.702l41.159,12.782l35.33,14.012l19.808,8.426l25.874,12.554l18.86,11.423l18.578,11.556l18.815,14.105l17.777,16.951l12.233,16.718l8.345,17.187l1.091,27.64l-7.434,8.207l-11.194,10.466l-15.595,10.559l-24.221,7.844l-22.609,5.211l-30.925,3.265l-43.658,0l-32.546,-2.085" style="fill:none;stroke-width:0px;stroke:#ff6060;"/>
    <g id="moon" style="transform: translateY(-130px) translateX(-53px);">
        <path d="M77.39,295.34c0,-10.683 -8.658,-19.343 -19.342,-19.343c-10.683,0 -19.344,8.66 -19.344,19.343c0,10.683 8.661,19.343 19.344,19.343c10.684,0 19.342,-8.66 19.342,-19.343" style="fill:#fff;fill-rule:nonzero;"/>
        <path d="M61.54,304.476c0,-2.967 -2.404,-5.373 -5.371,-5.373c-2.969,0 -5.373,2.406 -5.373,5.373c0,2.967 2.404,5.373 5.373,5.373c2.967,0 5.371,-2.406 5.371,-5.373" style="fill:#878787;fill-opacity:0.199997;fill-rule:nonzero;"/>

        <animateMotion dur="6s" repeatCount="indefinite">
            <mpath xlink:href="#orbit" />
        </animateMotion>
        <animateTransform attributeName="transform"
                      attributeType="XML"
                      type="rotate"
                      from="0 60 70"
                      to="360 60 70"
                      dur="10s"
                      repeatCount="indefinite"/>
    </g>
</svg>

4 个答案:

答案 0 :(得分:1)

您正在将CSS变换与变换属性的SMIL动画混合使用。虽然SVG 2表明它们应该是同一个东西,但SVG 1.1将它们作为不同的东西。在SVG 2的SVG 2规范和UA实现接近完成之前,最好不要混合使用这些东西。

我已经将g元素的转换转换为属性转换,动画片现在肯定会在Firefox上为我做点什么。

<iframe name="year" src="2015.html"></iframe>

答案 1 :(得分:-1)

容易!

AnimateTransform 标记必须

AnimateMotion 标记,完全封闭,不跟随。

答案 2 :(得分:-1)

进动轨道:

<?xml version="1.0"?>
<svg width="940" height="360"  viewBox="0 0 350 350"
 xmlns="http://www.w3.org/2000/svg" version="1.1"
 xmlns:xlink="http://www.w3.org/1999/xlink" >
<!-- Here is a red circle which will be moved along the     motion path. -->
<g>
  <path d="M10,110 A120,120 -45 0,1 110 10 A120,120 -45            0,1 10,110"
      stroke="lightgrey" stroke-width="2" 
      fill="none" id="theMotionPath"/
  <circle cx="470" cy="180" r="160" fill="paleblue" />     
  <circle cx="10" cy="110" r="3" fill="lightgrey"  />
  <circle cx="110" cy="10" r="3" fill="lightgrey"  />
        <circle cx="" cy="" r="10" fill="red">        
    <!-- Define the motion path animation -->
    <animateMotion dur="6s" repeatCount="indefinite">
  <animateTransform attributeName="transform"
                      attributeType="XML"
                      type="rotate"
                      from="0 440 190"
                      to="360 440 190"
                      dur="6s"
                      repeatCount="indefinite"/>
       <mpath xlink:href="#theMotionPath"/>
    </animateMotion>
 </circle>
 <animateTransform attributeName="transform"
                      attributeType="XML"
                      type="rotate"
                      from="0 60 70"
                      to="360 60 70"
                      dur="10s"
                      repeatCount="indefinite"/>

</g>                   
</svg>

根据自己的喜好复制,粘贴,编辑。

答案 3 :(得分:-2)

<!DOCTYPE html>
<div width="100%">
<svg style="background:plum" width="240px" height="120px"
 xmlns="http://www.w3.org/2000/svg" version="1.1"
 xmlns:xlink="http://www.w3.org/1999/xlink" >

<polygon points="60,30 90,90 30,90">
    <animateTransform attributeName="transform"
                      attributeType="XML"
                      type="rotate"
                      from="0 60 70"
                      to="360 60 70"
                      dur="10s"
                      repeatCount="indefinite"/>
</polygon>
</svg>
</div>