當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


SVG repeatCount屬性用法及代碼示例

repeatCount屬性指定動畫的持續時間。使用此屬性的元素包括<animate>,<animateColor>,<animateMotion>,<animateTransform>和<set>

用法:

repeatCount = number || indefinite

屬性值:repeatCount屬性接受上麵提到和下麵描述的值。

  • number:它指示迭代次數。值開始大於0或更大。
  • indefinite:它指定動畫將無限期重複。

範例1:下麵的示例說明了repeatCount屬性的用法。

HTML

<!DOCTYPE html> 
<html> 
  
<body> 
    <div style="color:green;  
          text-align:center;"> 
        <h1>GeeksforGeeks</h1> 
  
        <h4>It will stop after 6 sec.</h4> 
  
        <svg viewBox="0 0 620 150" 
            xmlns="http://www.w3.org/2000/svg"> 
              
            <rect x="260" y="0" fill="green" 
                width="100" height="100"> 
  
                <animate attributeType="XML" 
                    attributeName="y" from="0" 
                    to="50" dur="1s" repeatCount="6" /> 
            </rect> 
        </svg> 
    </div> 
</body> 
  
</html>

輸出:



範例2:

HTML

<!DOCTYPE html> 
<html> 
  
<body> 
    <div style="color:green;  
             text-align:center;"> 
        <h1>GeeksforGeeks</h1> 
  
        <h4>It will continue to animate</h4> 
  
        <svg viewBox="0 0 620 150" 
            xmlns="http://www.w3.org/2000/svg"> 
              
            <rect x="260" y="0" fill="green" 
                width="100" height="100"> 
                  
                <animate attributeType="XML" 
                    attributeName="y" from="0" 
                    to="50" dur="1s" 
                    repeatCount="indefinite" /> 
            </rect> 
        </svg> 
    </div> 
</body> 
  
</html>

輸出:




相關用法


注:本文由純淨天空篩選整理自thacker_shahid大神的英文原創作品 SVG repeatCount attribute。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。