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

View in English Always switch to English

SVGLineElement: y2 プロパティ

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月.

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

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

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="5%" x2="30%" y2="60%" stroke="red" stroke-width="4" />
</svg>

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

js
const lines = document.querySelectorAll("line");
const y2Pos0 = lines[0].y2;
const y2Pos1 = lines[1].y2;
console.dir(y2Pos0.baseVal.value); // 出力: 50 (the value of `y2`)
console.dir(y2Pos1.baseVal.value); // 出力: 120 (60% of 200)

仕様書

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGLineElement__y2

ブラウザーの互換性

関連情報