From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/touchevent/targettouches/index.html | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 files/zh-cn/web/api/touchevent/targettouches/index.html (limited to 'files/zh-cn/web/api/touchevent/targettouches') diff --git a/files/zh-cn/web/api/touchevent/targettouches/index.html b/files/zh-cn/web/api/touchevent/targettouches/index.html new file mode 100644 index 0000000000..5b09634380 --- /dev/null +++ b/files/zh-cn/web/api/touchevent/targettouches/index.html @@ -0,0 +1,60 @@ +--- +title: TouchEvent.targetTouches +slug: Web/API/TouchEvent/targetTouches +translation_of: Web/API/TouchEvent/targetTouches +--- +

{{ APIRef("Touch Events") }}

+ +

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

+ +

语法

+ +
var touches = touchEvent.targetTouches;
+
+ +

返回值

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

例子

+ +

本例阐述了 {{domxref("TouchEvent")}} 对象的 {{domxref("TouchEvent.targetTouches")}} 属性。{{domxref("TouchEvent.targetTouches")}} 属性也是一个 {{domxref("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);
+}
+ +

规格

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Touch Events 2','#widl-TouchEvent-targetTouches')}}{{Spec2('Touch Events 2')}}Non-stable version.
{{SpecName('Touch Events','#widl-TouchEvent-targetTouches')}}{{Spec2('Touch Events')}}Initial definition.
+ + + +

浏览器兼容性

+ +

{{Compat("api.TouchEvent.targetTouches")}}

-- cgit v1.2.3-54-g00ecf