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
, wobei die Parameter sx
und sy
die Skalierungsbeträge definieren.
Syntax
js
SVGTransform.setScale(sx, sy)
Parameter
Rückgabewert
Keiner (undefined
).
Ausnahmen
NoModificationAllowedError
DOMException
-
Wird ausgelöst, wenn das Attribut oder das
SVGTransform
-Objekt schreibgeschützt ist.
Beispiele
Skalieren 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
BCD tables only load in the browser