TouchEvent.touches

Limited availability

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

概要

一个 TouchList,其会列出所有当前在与触摸表面接触的 Touch 对象,不管触摸点是否已经改变或其目标元素是在处于 touchstart 阶段。

此属性是 只读

语法

var touches = touchEvent.touches;

返回值

touches

一个 TouchList,其会列出所有当前在与触摸表面接触的 Touch 对象,不管触摸点是否已经改变或其目标元素是在处于 touchstart 阶段。

示例

此示例说明 TouchEvent 对象的 TouchEvent.touches 属性。该TouchEvent.touches 属性是一个 TouchList 对象,并包含 Touch 当前接触表面的每个接触点的对象列表。

在下面的代码片段中,touchstart 事件处理程序会检查 TouchEvent.touches 列表的长度,以确定激活的触摸点的数量,然后根据触摸点的数量调用不同的处理程序。

js
someElement.addEventListener(
  "touchstart",
  function (e) {
    // Invoke the appropriate handler depending on the
    // number of touch points.
    switch (e.touches.length) {
      case 1:
        handle_one_touch(e);
        break;
      case 2:
        handle_two_touches(e);
        break;
      case 3:
        handle_three_touches(e);
        break;
      default:
        console.log("Not supported");
        break;
    }
  },
  false,
);

规范

Specification
Touch Events
# dom-touchevent-touches

浏览器兼容性

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
touches

Legend

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

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