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


SVG LinearGradientElement.y2屬性用法及代碼示例

SVG LinearGradientElement.y2屬性返回與給定LinearGradient元素的屬性相對應的SVGAnimatedLength對象

用法:

LinearGradientElement.y2

返回值:該屬性返回可以使用的SVGAnimatedLength對象獲取y2的LinearGradient元素。

範例1:

HTML

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg viewBox="0 0 200 200" 
        xmlns="http://www.w3.org/2000/svg" 
        xmlns:xlink="http://www.w3.org/1999/xlink"> 
          
        <defs> 
            <linearGradient id="gfg" 
                gradientTransform="rotate(70)" 
                x1="0%" x2="20%" y1="0%" y2="20%"> 
                  
                <stop offset="10%" stop-color="blue" /> 
                <stop offset="90%" stop-color="green" /> 
            </linearGradient> 
        </defs> 
  
        <circle cx="20" cy="20" r="20" fill="url('#gfg')" /> 
          
        <script> 
            var a = document.getElementById("gfg"); 
            console.log(a.y2); 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:



範例2:

HTML

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg viewBox="0 0 500 500" 
        xmlns="http://www.w3.org/2000/svg" 
        xmlns:xlink="http://www.w3.org/1999/xlink"> 
          
        <defs> 
            <linearGradient id="gfg" 
                gradientTransform="rotate(70)" 
                x1="0%" x2="20%" y1="0%" y2="20%"> 
                  
                <stop offset="10%" stop-color="blue" /> 
                <stop offset="90%" stop-color="green" /> 
            </linearGradient> 
        </defs> 
  
        <ellipse cx="100" cy="70" rx="80" 
            ry="50" fill="url('#gfg')" /> 
              
        <script> 
            var a = document.getElementById("gfg"); 
            console.log(a.y2); 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:

範例3:

HTML

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg viewBox="0 0 500 500" 
        xmlns="http://www.w3.org/2000/svg" 
        xmlns:xlink="http://www.w3.org/1999/xlink"> 
          
        <defs> 
            <linearGradient id="gfg" 
                gradientTransform="rotate(70)" 
                x1="0%" x2="20%" y1="0%" y2="20%"> 
                  
                <stop offset="10%" stop-color="blue" /> 
                <stop offset="90%" stop-color="green" /> 
            </linearGradient> 
        </defs> 
  
        <rect height="80" width="80" x="30" 
            y="30" fill="url('#gfg')" /> 
              
        <script> 
            var a = document.getElementById("gfg"); 
            console.log(a.y2); 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:




相關用法


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