SVGTransform: setScale()-Methode

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 setScale()-Methode des SVGTransform-Interfaces setzt den Transformationstyp auf SVG_TRANSFORM_SCALE. Die Parameter sx und sy definieren die Skalierungsfaktoren.

Syntax

js
setScale(sx, sy)

Parameter

sx

Ein Float, der den Skalierungsfaktor entlang der X-Achse definiert.

sy

Ein Float, der den Skalierungsfaktor entlang der Y-Achse definiert.

Rückgabewert

Keiner (undefined).

Ausnahmen

NoModificationAllowedError DOMException

Wird geworfen, wenn das Attribut oder das SVGTransform-Objekt schreibgeschützt ist.

Beispiele

Skalierung eines SVG-Elements

js
// Select an SVG element and create a transform object
const svgElement = document.querySelector("svg");
const transform = svgElement.createSVGTransform();

// Set the scale values for the transform
transform.setScale(2, 3);

// Output the scale details
console.log(`Scale X: ${transform.matrix.a}`); // Output: 2
console.log(`Scale Y: ${transform.matrix.d}`); // Output: 3

Spezifikationen

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGTransform__setScale

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
setScale

Legend

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

Full support
Full support