SVGTextPositioningElement: thuộc tính dy

Baseline Widely available

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

Thuộc tính chỉ đọc dy của giao diện SVGTextPositioningElement mô tả tọa độ trục y của SVGTextElement hoặc SVGTSpanElement dưới dạng SVGAnimatedLengthList. Nó phản ánh độ dịch chuyển dọc của các ký tự văn bản riêng lẻ trong hệ tọa độ người dùng theo thuộc tính dy.

Giá trị thuộc tính là danh sách các <length>, <percentage>, hoặc <number>. Các giá trị số trong SVGAnimatedLengthList.baseVal phản ánh độ dịch chuyển dọc trong hệ tọa độ người dùng.

Giá trị

Một SVGAnimatedLengthList.

Ví dụ

Cho SVG sau:

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

Chúng ta có thể truy cập các giá trị đã tính toán của thuộc tính dy:

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

console.log(texts[0].dy.baseVal[0].value); // output: 5
console.log(texts[1].dy.baseVal[0].value); // output: 10

Thông số kỹ thuật

Thông số kỹ thuật
Scalable Vector Graphics (SVG) 2
# __svg__SVGTextPositioningElement__dy

Tương thích trình duyệt

Xem thêm