SVGPathElement: pathLength 屬性

SVGPathElement 介面的只讀屬性 pathLength 反映了給定 <path> 元素的 pathLength 屬性。

一個 SVGAnimatedNumber

示例

訪問 pathLength 屬性

html
<svg width="200" height="100">
  <path id="myPath" d="M 0,30 h100" pathLength="50" />
</svg>
js
const pathElement = document.getElementById("myPath");

// Access the pathLength property
const animatedNumber = pathElement.pathLength;

// The base value of the pathLength attribute
console.log(animatedNumber.baseVal); // Output: 100

規範

規範
SVG 路徑
# __svg__SVGPathElement__pathLength

瀏覽器相容性

另見