TouchEvent.touches

概要

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

此属性是 只读

语法

var touches = touchEvent.touches;

返回值

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

示例

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

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

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);

规范

规范 状态 评价
Touch Events – Level 2 Draft 不稳定版
Touch Events Recommendation 初始定义

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
touchesChrome Full support 22Edge Full support YesFirefox Full support 52
Full support 52
No support 18 — 24
IE No support NoOpera Full support YesSafari No support NoWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 6Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support