大网数据广告活动
Web 标准与前端开发

SVGLineElement: y1 property

· 52CE 我爱测

The **`y1`** read-only property of the SVGLineElement interface describes the start of the SVG line along the y-axis as an SVGAnimatedLength. It reflects the line element's y1 geometric attribute.

SVG

The y1 read-only property of the SVGLineElement interface describes the start of the SVG line along the y-axis as an SVGAnimatedLength. It reflects the line element's y1 geometric attribute.

The attribute value is a <length>, <percentage>, or <number>. The numeric value of the SVGAnimatedLength.baseVal is that start position as a length along the y-axis in user coordinate system units.

Value

An SVGAnimatedLength.

Example

Given the following SVG:

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

We can access the computed values of the y1 attributes:

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

Specifications

Browser compatibility

See also

  • SVGLineElement.y2
  • SVGAnimatedLength.baseVal

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。