このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

SVGLineElement: x2 プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.

x2SVGLineElement インターフェイスの読み取り専用プロパティで、線の終点の X 軸座標値を SVGAnimatedLength として記述します。これは、<line> 要素の x2 属性の計算値を反映します。

この属性の値は <length><percentage><number> のいずれかです。SVGAnimatedLength.baseVal の値は、ユーザー座標系における終点を X 軸方向の長さで表します。

SVGAnimatedLength です。

次の SVG があったとします。

html
<svg viewBox="0 0 300 200" xmlns="http://www.w3.org/2000/svg">
  <line x1="20" y1="30" x2="40" y2="50" stroke="blue" stroke-width="2" />
  <line x1="15%" y1="0" x2="30%" y2="60" stroke="red" stroke-width="4" />
</svg>

x2 属性の計算値には、次のようにアクセスできます。

js
const lines = document.querySelectorAll("line");
const x2Pos0 = lines[0].x2;
const x2Pos1 = lines[1].x2;
console.dir(x2Pos0.baseVal.value); // 出力: 40 (the value of `x2`)
console.dir(x2Pos1.baseVal.value); // 出力: 90 (30% of 300)

仕様書

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGLineElement__x2

ブラウザーの互換性

関連情報