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

View in English Always switch to English

SVGLineElement: y1 プロパティ

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

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

この属性の値は <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>

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

js
const lines = document.querySelectorAll("line");
const y1Pos0 = lines[0].y1;
const y1Pos1 = lines[1].y1;
console.dir(y1Pos0.baseVal.value); // 出力: 30 (the value of `y1`)
console.dir(y1Pos1.baseVal.value); // 出力: 10 (5% of 200)

仕様書

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGLineElement__y1

ブラウザーの互換性

関連情報