SVGAngle: convertToSpecifiedUnits() 方法
SVGAngle 介面的 convertToSpecifiedUnits() 方法允許您將角度值轉換為指定的單位型別。
此函式將
- 將
unitType屬性設定為給定的單位型別 - 更新
valueInSpecifiedUnits和valueAsString屬性,以便角度值以給定的單位型別表示
語法
js
convertToSpecifiedUnits(unitType)
引數
返回值
無(undefined)。
示例
將角度轉換為度
js
// Get an SVGAngle object
const svg = document.querySelector("svg");
const angle = svg.createSVGAngle();
// Set the angle's value in radians (Math.PI / 2)
angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_RAD, Math.PI / 2);
// Retrieve the angle's value as a string
console.log(angle.valueAsString); // Output: 1.5708rad
console.log(angle.unitType); // Output: 3 (SVG_ANGLETYPE_RAD)
// Convert the angle's value to degrees
angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG);
// Retrieve the angle's value as a string
console.log(angle.valueAsString); // Output: 90deg
console.log(angle.unitType); // Output: 2 (SVG_ANGLETYPE_DEG)
規範
| 規範 |
|---|
| Scalable Vector Graphics (SVG) 2 # __svg__SVGAngle__convertToSpecifiedUnits |
瀏覽器相容性
載入中…