TouchEvent.targetTouches

Limited availability

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

targetTouches 是一个只读的 TouchList 列表,包含仍与触摸面接触的所有触摸点的 Touch 对象。touchstart事件触发在哪个element内,它就是当前目标元素。

语法

js
var touches = touchEvent.targetTouches;

返回值

touches

一个 TouchList,包含仍与触摸面接触的所有触摸点的 Touch 对象,touchstart事件触发在哪个element内,它就是当前目标元素。

例子

本例阐述了 TouchEvent 对象的 TouchEvent.targetTouches 属性。TouchEvent.targetTouches 属性也是一个 TouchList,其中包含的触摸点起始于触摸事件当前的目标元素,并且此刻正在触摸屏幕。所以,targetTouches 元素是 touches 的真子集。

下面代码段中的函数比较了 touches 列表和 targetTouches 列表的长度,返回值表示他们是否相等。

js
function touches_in_target(ev) {
  // Return true if all of the touches are within the target element;
  // otherwise return false.
  return ev.touches.length == ev.targetTouches.length ? true : false;
}

规范

Specification
Touch Events
# dom-touchevent-targettouches

浏览器兼容性

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
targetTouches

Legend

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

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