SVGSymbolElement: viewBox-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 viewBox-Eigenschaft der SVGSymbolElement-Schnittstelle ist eine schreibgeschützte Eigenschaft, die das viewBox-Attribut des angegebenen <symbol>-Elements widerspiegelt.

Wert

Ein SVGAnimatedRect-Objekt.

Beispiele

Zugriff auf die viewBox-Eigenschaft

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");

// Access the viewBox property
const viewBox = symbolElement.viewBox.baseVal;

console.log(viewBox.x); // Output: 0
console.log(viewBox.y); // Output: 0
console.log(viewBox.width); // Output: 100
console.log(viewBox.height); // Output: 100

Spezifikationen

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGFitToViewBox__viewBox

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
viewBox

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Siehe auch