TouchList: item()-Methode

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Die item()-Methode gibt das Touch-Objekt am angegebenen Index in der TouchList zurück.

Syntax

js
item(index)

Parameter

index

Der Index des Touch-Objekts, das abgerufen werden soll. Der Index ist eine Zahl im Bereich von 0 bis zur Länge der TouchList minus eins.

Rückgabewert

touchPoint

Das angeforderte Touch-Objekt aus der TouchList. Gibt null zurück, wenn der Index nicht kleiner als die Länge der Liste ist.

Beispiele

Dieses Codebeispiel veranschaulicht die Verwendung der item-Methode der TouchList-Schnittstelle und der length-Eigenschaft.

js
const target = document.getElementById("target");

target.addEventListener(
  "touchstart",
  (ev) => {
    // If this touchstart event started on element target,
    // set touch to the first item in the targetTouches list;
    // otherwise set touch to the first item in the touches list
    const touch =
      ev.targetTouches.length >= 1
        ? ev.targetTouches.item(0)
        : ev.touches.item(0);
  },
  false,
);

Spezifikationen

Specification
Touch Events
# dom-touchlist-item

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
item

Legend

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

Full support
Full support
Partial support
Partial support
No support
No support
Has more compatibility info.