SVGPointList: initialize()-Methode

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Die initialize()-Methode der SVGPointList-Schnittstelle löscht die Liste und fügt dann ein einzelnes neues SVGPoint-Objekt zur Liste hinzu.

Syntax

js
initialize(obj)

Parameter

obj

Ein SVGPoint-Objekt, das die Koordinaten des Punktes enthält, der hinzugefügt werden soll, wenn die Liste initialisiert wird.

Rückgabewert

Das hinzugefügte SVGPoint-Objekt.

Ausnahmen

NoModificationAllowedError DOMException

Wird geworfen, wenn die Liste nur-lesbar ist.

Beispiele

Das folgende Beispiel zeigt ein SVG, das ein <polyline> mit fünf Koordinatenpaaren enthält. Die Rückgabe von SVGPointList.length gibt den Wert 5 zurück. Nach dem Aufruf von initialize() gibt die Rückgabe von SVGPointList.length den Wert 1 zurück.

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
let example = document.getElementById("example");
console.log(example.points.length); //5;
let svgPoint = document.getElementById("svg").createSVGPoint();
example.points.initialize(svgPoint);
console.log(example.points.length); //1

Spezifikationen

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGNameList__initialize

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
initialize

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support