SVGPointList: getItem() 方法

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

SVGPointList 介面的 getItem() 方法可以根據指定的索引從列表中獲取一個項。

語法

js
getItem(index)

引數

index

要返回的項的索引。

返回值

一個 DOMPoint 物件。

異常

IndexSizeError DOMException

如果傳入的索引大於列表中的項數,則會丟擲此異常。

示例

下面的示例展示了一個包含帶有五個座標對的 <polyline> 元素的 SVG。索引為 0DOMPoint

html
<svg id="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.getItem(0));

規範

規範
Scalable Vector Graphics (SVG) 2
# __svg__SVGNameList__getItem

瀏覽器相容性