SVGSymbolElement: viewBox property

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 viewBox của giao diện SVGSymbolElement phản ánh thuộc tính viewBox của phần tử <symbol> tương ứng.

Giá trị

Một đối tượng SVGAnimatedRect.

Ví dụ

Truy cập thuộc tính viewBox

html
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">
  <defs>
    <symbol id="exampleSymbol" viewBox="0 0 100 100">
      <circle cx="50" cy="50" r="50" fill="blue" />
    </symbol>
  </defs>
  <use href="#exampleSymbol" x="50" y="50" width="100" height="100" />
</svg>
js
const symbolElement = document.getElementById("exampleSymbol");

// Truy cập thuộc tính viewBox
const viewBox = symbolElement.viewBox.baseVal;

console.log(viewBox.x); // Kết quả: 0
console.log(viewBox.y); // Kết quả: 0
console.log(viewBox.width); // Kết quả: 100
console.log(viewBox.height); // Kết quả: 100

Thông số kỹ thuật

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

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

Xem thêm