SVGTransform:setScale() 方法

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

SVGTransform 介面的 setScale() 方法將變換型別設定為 SVG_TRANSFORM_SCALE,引數 sxsy 定義縮放量。

語法

js
setScale(sx, sy)

引數

sx

一個定義 X 軸縮放量的浮點數。

sy

一個定義 Y 軸縮放量的浮點數。

返回值

無(undefined)。

異常

NoModificationAllowedError DOMException

如果屬性或 SVGTransform 物件是隻讀的,則丟擲此異常。

示例

縮放 SVG 元素

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

規範

規範
Scalable Vector Graphics (SVG) 2
# __svg__SVGTransform__setScale

瀏覽器相容性