SVGTextContentElement:textLength 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

SVGTextContentElement 介面的只讀屬性 textLength 反映了給定元素的 textLength 屬性。

一個 SVGAnimatedLength 物件。

示例

訪問 textLength 屬性

html
<svg width="200" height="100">
  <text id="myText" x="10" y="50" textLength="100" lengthAdjust="spacing">
    Hello, SVG!
  </text>
</svg>
js
const textElement = document.getElementById("myText");

// Access the textLength property
const animatedLength = textElement.textLength;

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

規範

規範
Scalable Vector Graphics (SVG) 2
# __svg__SVGTextContentElement__textLength

瀏覽器相容性

另見