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

浏览器兼容性

另见