2012-08-06 25 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