2012-08-06 51 views
12

我想使svg路径的不透明度从0到100回到0并在连续循环中回到100。循环中的SVG动画不透明度

到目前为止,我可以得到它从0到动画100但不回来,

任何想法?

感谢

+1

我们可以看到迄今为止的代码吗? (如果你愿意的话,将它编辑到你的文章中)。 – halfer 2012-08-06 12:41:50

回答

19

你有两个独立的动画 - 一个不透明度增加,一个是它降低。每一个都从另一端开始,但第一个也从0开始。下面是一个矩形的例子:

<rect x="10" y="10" width="20" height="20"> 
    <animate id="animation1" 
      attributeName="opacity" 
      from="0" to="1" dur="1s" 
      begin="0s;animation2.end" /> 
    <animate id="animation2" 
      attributeName="opacity" 
      from="1" to="0" dur="1s" 
      begin="animation1.end" /> 
</rect> 
+1

已弃用元素:( – 2015-09-09 13:23:59

+0

@DougChamberlain不推荐元素?对我来说工作正常 – Cyborg 2017-05-10 14:23:06

37

可以使用values属性,像这样动画任何数量的值:

<rect x="10" y="10" width="20" height="20"> 
    <animate attributeName="opacity" 
      values="0;1;0" dur="1s" 
      repeatCount="indefinite"/> 
</rect> 

这将动画从不透明0到不透明度1(100%),然后在1秒的时间内再次回到0。

+3

^^更佳回答 – IvanM 2014-03-14 10:25:28

+0

这似乎没有重复..可能需要'repeatCount =“indefinite”' – 2014-06-07 09:14:01

+0

谢谢@StevenLu,已更新。 – 2014-06-09 11:49:14