blob: 5b09634380b50e108c00afeb108101a249e51376 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
---
title: TouchEvent.targetTouches
slug: Web/API/TouchEvent/targetTouches
translation_of: Web/API/TouchEvent/targetTouches
---
<p id="Summary">{{ APIRef("Touch Events") }}</p>
<p><strong><code>targetTouches</code></strong> 是一个只读的 {{ domxref("TouchList") }} 列表,包含仍与触摸面接触的所有触摸点的 {{ domxref("Touch") }} 对象。{{event("touchstart")}}事件触发在哪个{{ domxref("element") }}内,它就是当前目标元素。</p>
<h2 id="Syntax" name="Syntax">语法</h2>
<pre class="brush: js">var <em>touches</em> = <em>touchEvent</em>.targetTouches;
</pre>
<h3 id="Return_Value" name="Return_Value">返回值</h3>
<dl>
<dt><code>touches</code></dt>
<dd>一个 {{ domxref("TouchList") }},包含仍与触摸面接触的所有触摸点的 {{ domxref("Touch") }} 对象,{{event("touchstart")}}事件触发在哪个{{ domxref("element") }}内,它就是当前目标元素。</dd>
</dl>
<h2 id="Specification" name="Specification">例子</h2>
<p>本例阐述了 {{domxref("TouchEvent")}} 对象的 {{domxref("TouchEvent.targetTouches")}} 属性。{{domxref("TouchEvent.targetTouches")}} 属性也是一个 {{domxref("TouchList")}},其中包含的触摸点起始于触摸事件当前的目标元素,并且此刻正在触摸屏幕。所以,<font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">targetTouches</span></font> 元素是 <code>touches</code> 的真子集。</p>
<p>下面代码段中的函数比较了 <code>touches</code> 列表和 <code>targetTouches</code> 列表的长度,返回值表示他们是否相等。</p>
<pre class="brush: 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);
}</pre>
<h2 id="Specification" name="Specification">规格</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('Touch Events 2','#widl-TouchEvent-targetTouches')}}</td>
<td>{{Spec2('Touch Events 2')}}</td>
<td>Non-stable version.</td>
</tr>
<tr>
<td>{{SpecName('Touch Events','#widl-TouchEvent-targetTouches')}}</td>
<td>{{Spec2('Touch Events')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p>{{Compat("api.TouchEvent.targetTouches")}}</p>
|