SVGAngle: convertToSpecifiedUnits() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
convertToSpecifiedUnits()
は SVGAngle
インターフェイスのメソッドで、角度の値を指定した単位型に変換することができます。
この関数は次のことを行います。
- 指定された単位型で
unitType
プロパティを更新する valueInSpecifiedUnits
およびvalueAsString
プロパティを更新し、角度値が指定された単位型で表現されるようにする
構文
js
convertToSpecifiedUnits(unitType)
引数
返値
なし (undefined
)。
例
角度を度に変換
js
// SVGAngle オブジェクトを取得
const svg = document.querySelector("svg");
const angle = svg.createSVGAngle();
// 角度の値をラジアンで設定 (Math.PI / 2)
angle.newValueSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_RAD, Math.PI / 2);
// 角度の値を文字列として受け取る
console.log(angle.valueAsString); // 出力: 1.5708rad
console.log(angle.unitType); // 出力: 3 (SVG_ANGLETYPE_RAD)
// 角度の値を度に変換
angle.convertToSpecifiedUnits(SVGAngle.SVG_ANGLETYPE_DEG);
// 角度の値を文字列として受け取る
console.log(angle.valueAsString); // 出力: 90deg
console.log(angle.unitType); // 出力: 2 (SVG_ANGLETYPE_DEG)
仕様書
Specification |
---|
Scalable Vector Graphics (SVG) 2 # __svg__SVGAngle__convertToSpecifiedUnits |