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

View in English Always switch to English

SVGLineElement: x1 プロパティ

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

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

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

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

js
const lines = document.querySelectorAll("line");
const x1Pos0 = lines[0].x1;
const x1Pos1 = lines[1].x1;
console.dir(x1Pos0.baseVal.value); // 出力: 20 (the value of `x1`)
console.dir(x1Pos1.baseVal.value); // 出力: 45 (15% of 300)

仕様書

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGLineElement__x1

ブラウザーの互換性

関連情報