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 |
浏览器兼容性
加载中…