TouchEvent.targetTouches

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

语法

var touches = touchEvent.targetTouches;

返回值

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

例子

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

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

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 Status Comment
Touch Events – Level 2 Draft Non-stable version.
Touch Events Recommendation Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
targetTouchesChrome Full support 22Edge Full support ≤18Firefox 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