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


SVG CircleElement.cx屬性用法及代碼示例

SVG CircleElement.cx屬性返回與給定lin屬性相對應的SVGAnimatedLength對象e元件。

用法:

CircleElement.cx

返回值:此屬性返回可以使用的SVGAnimatedLength對象獲取circle元素的cx。

範例1:

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 250 250" width="250" 
        height="250"> 
          
        <circle cx="100" cy="100" r="50" 
            fill="green" id="gfg" 
            onclick="clickCircle();" /> 
          
        <script> 
            var g = document.getElementById("gfg"); 
            console.log(g.cx) 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:



範例2:

HTML

<!DOCTYPE html> 
<html> 
  
<body> 
    <svg xmlns="http://www.w3.org/2000/svg"
        viewBox="0 0 250 250" width="250" 
        height="250"> 
          
        <circle cx="100" cy="100" r="50" 
            fill="green" class="gfg" 
            onclick="clickCircle();" /> 
          
        <script> 
            function clickCircle() { 
                var g = document.querySelector(".gfg"); 
                document.write("cx value of the circle is:", 
                    g.cx.animVal.value); 
            } 
        </script> 
    </svg> 
</body> 
  
</html>

輸出:




相關用法


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