SVGPointList

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

SVGPointList 接口表示一个 DOMPoint 对象列表。

SVGPointList 可以被指定为只读,这意味着尝试修改该对象将导致抛出异常。

实例属性

SVGPointList.length 只读

返回列表中点的数量。

SVGPointList.numberOfItems 只读

返回列表中点的数量。

实例方法

SVGPointList.clear()

移除列表中的所有项。

SVGPointList.initialize()

首先移除列表中的所有项,然后向列表中添加单个值。

SVGPointList.getItem()

获取列表中指定位置的项。

SVGPointList.insertItemBefore()

在指定位置将元素插入列表。

SVGPointList.replaceItem()

用新项替换列表中的一项。

SVGPointList.removeItem()

从列表中移除一项。

SVGPointList.appendItem()

将一项添加到列表末尾。

示例

以下示例显示了一个包含具有五个坐标对的 <polyline> 的 SVG。points 属性返回一个 SVGPointList

html
<svg viewBox="-10 -10 120 120" xmlns="http://www.w3.org/2000/svg">
  <polyline
    id="example"
    stroke="black"
    fill="none"
    points="50,0 21,90 98,35 2,35 79,90" />
</svg>
js
const example = document.getElementById("example");
console.log(example.points); // An SVGPointList

规范

规范
Scalable Vector Graphics (SVG) 2
# 接口SVGPointList

浏览器兼容性