TouchList: item() メソッド

Limited availability

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

item() メソッドは、この TouchList の中の指定された位置にある Touch オブジェクトを返します。

構文

js
item(index)

引数

index

取得する Touch オブジェクトの添字を指定します。添字は、0 から TouchList の長さより 1 つ小さい数までの数です。

返値

touchPoint

要求された Touch オブジェクトを TouchList から取得したものです。 添字がリストの長さ以上の場合は null を返します。

このコード例では、TouchList インターフェイスの item メソッドと length プロパティの使い方を示しています。

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

target.addEventListener(
  "touchstart",
  (ev) => {
    // この touchstart イベントが対象要素で始まった場合、touch を
    // targetTouches リストの最初の項目に設定します。そうでない
    // 場合は、touch リストの最初の項目に touch を設定します。
    const touch =
      ev.targetTouches.length >= 1
        ? ev.targetTouches.item(0)
        : ev.touches.item(0);
  },
  false,
);

仕様書

Specification
Touch Events
# dom-touchlist-item

ブラウザーの互換性

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.