SVGTextPositioningElement: y-Eigenschaft

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Die y-schreibgeschützte Eigenschaft des SVGTextPositioningElement-Interfaces beschreibt die y-Achsen-Koordinate des SVGTextElement, SVGTSpanElement oder SVGTRefElement als eine SVGAnimatedLengthList. Sie spiegelt das y-Attribut wider, welches die vertikale Position der einzelnen Textglyphen im Benutzerkoordinatensystem angibt.

Der Attributwert ist eine Liste aus <length>, <percentage> oder <number>. Die numerischen Werte in der SVGAnimatedLengthList.baseVal spiegeln die y-Koordinaten im Benutzerkoordinatensystem wider.

Wert

Beispiele

Gegeben sei das folgende SVG:

html
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
  <text x="10" y="20">Hello</text>
  <text x="50" y="50">World</text>
</svg>

Wir können auf die berechneten Werte der y-Attribute zugreifen:

js
const texts = document.querySelectorAll("text");

console.log(texts[0].y.baseVal[0].value); // output: 20
console.log(texts[1].y.baseVal[0].value); // output: 50

Spezifikationen

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGTextPositioningElement__y

Browser-Kompatibilität

BCD tables only load in the browser

Siehe auch