2015-05-27 62 views
0

目前,我有以下SVG,并希望动画路径:简单的SVG缩放

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" 
width="112.5px" height="115.4px" viewBox="0 0 112.5 115.4" enable-background="new 0 0 112.5 115.4" xml:space="preserve"> 

    <g> 
     <ellipse fill="#333333" cx="56.3" cy="56.3" rx="56.3" ry="56.3"/> 
    </g> 

    <g> 
     <path fill="none" class="iphone-feature-icon-heart-path" stroke="#FFFFFF" stroke-width="2" stroke-miterlimit="10" d="M82.6,50L82.6,50c-0.2-8.1-6.9-15.2-15.1-15.2 
      c-4.8,0-9,2.4-11.8,6c-2.8-3.6-7-6-11.8-6c-8.3,0-15,7.2-15.1,15.2h0c0,0,0,0.1,0,0.1c0,0,0,0.1,0,0.1c0,0.2,0.1,0.4,0.1,0.6 
      c0.7,20.5,26.6,29,26.6,29s26.3-8.4,27.1-28.9c0-0.2,0.1-0.4,0.1-0.6c0,0,0-0.1,0-0.1C82.6,50.1,82.6,50.1,82.6,50z"/> 

    </g> 

A“脉冲”沿路径的原点动画就是希望。我试过在最后一组之间放弃这个,但是有一些问题。首先,它不会回到原始尺度。

<animateTransform attributeType="XML" 
    attributeName="transform" type="scale" 
    from="1 1" to="1.5 1.5" 
    begin="0s" dur="2s" fill="freeze"/> 

其次,它并不沿着路径的中心点进行缩放。我曾考虑使用变换原点50%,50%,并在css中做脉冲,但是这在firefox中不起作用(或者至少它不会沿着真实原点生成动画)。

请参阅小提琴: http://jsfiddle.net/y1kdna46/3/

从阅读各地看来,似乎有一个转换矩阵,可以用来做这个跨浏览器。任何提示/建议?尽我所能,我希望避免CSS/JavaScript来执行此操作。即在SVG的代码中完成。

回答

1

这似乎是正确的。我已经对路径进行了转换,以便对原点进行缩放并使用值执行操作,然后撤消缩放。还请注意additive =“sum”,所以我不会覆盖我的初始转换。

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" 
 
\t width="112.5px" height="115.4px" viewBox="0 0 112.5 115.4" xml:space="preserve"> 
 

 
\t \t <g> 
 
\t \t \t <ellipse fill="#333333" cx="56.3" cy="56.3" rx="56.3" ry="56.3"/> 
 
\t \t </g> 
 

 
\t \t <g transform="translate(50, 50)"> 
 
\t \t \t <path transform="translate(-50, -50)" fill="none" class="iphone-feature-icon-heart-path" stroke="#FFFFFF" stroke-width="2" stroke-miterlimit="10" d="M82.6,50L82.6,50c-0.2-8.1-6.9-15.2-15.1-15.2 
 
\t \t \t \t c-4.8,0-9,2.4-11.8,6c-2.8-3.6-7-6-11.8-6c-8.3,0-15,7.2-15.1,15.2h0c0,0,0,0.1,0,0.1c0,0,0,0.1,0,0.1c0,0.2,0.1,0.4,0.1,0.6 
 
\t \t \t \t c0.7,20.5,26.6,29,26.6,29s26.3-8.4,27.1-28.9c0-0.2,0.1-0.4,0.1-0.6c0,0,0-0.1,0-0.1C82.6,50.1,82.6,50.1,82.6,50z"/> 
 
\t \t \t \t <animateTransform attributeType="XML" 
 
     attributeName="transform" type="scale" 
 
      values="1;1.5;1" additive="sum" 
 
     begin="0s" dur="2s" repeatCount="indefinite"/> 
 
\t \t </g> 
 

 

 
</svg>

+0

传奇。工作过一种享受。 – Paul