本文介绍了e.touches,e.targetTouches和e.changedTouches的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在收听 touchstart touchmove touchend 正文元素。

Let's say I am listening for touchstart, touchmove and touchend on the body element.

如果我错了,请告诉我,但我认为 e.touches e.targetTouches 相同?如果是这样, e.changedTouches 与他们有何不同?

Let me know if I'm wrong, but I think e.touches is the same as e.targetTouches? If so, how e.changedTouches varies in relation with them?

我的意思是,只要在一个特定时刻触摸,我就会获取touchevent并解析它。根据我的经验,所有三个触摸变量都是相同的。

I mean, given one touch at one given moment, I fetch the touchevent and parse it. In my experience all three touch variables are the same.

我必须将解析后的数据发送到服务器,并且发送三次完全相同的字符串是非常多余的,是不是有任何方法可以将它们发送一次并以编程方式发送重现服务器上的touchevent?

I have to send the parsed data to the server and it's quite redundant to send three times the same exact string, isn't there any way to send them once and programatically reproduce the touchevent on the server?

推荐答案

我们有以下列表:


  • 触摸:当前触摸屏幕的每个手指的信息列表

  • targetTouches :与触摸类似,但仅过滤到同一节点内开始的手指触摸信息

  • changedTouches :事件中涉及的每个手指的信息列表

  • touches: A list of information for every finger currently touching the screen
  • targetTouches: Like touches, but is filtered to only the information for finger touches that started out within the same node
  • changedTouches: A list of information for every finger involved in the event

为了更好地理解这些中可能包含的内容列表,让我们快速回顾一些例子。它们根据以下规则而有所不同:

To better understand what might be in these lists, let’s go over some examples quickly. They vary according to the following rules:


  • 当我放下手指时,所有三个列表都将具有相同的信息。它将在 changedTouches 中,因为将手指放下是导致事件发生的原因

  • 当我放下第二根手指时, touches 将有两个项目,每个手指一个。只有当手指与第一根手指放在同一节点时, targetTouches 才会有两项。 changedTouches 将获得与第二根手指相关的信息,因为它是造成事件的原因

  • 如果我把两根手指放在正确的位置同时,可以在 changedTouches 中有两个项目,每个手指一个

  • 如果我移动我的手指,唯一的列表是将更改是 changedTouches 并将包含与移动的手指数量相关的信息(至少一个)。

  • 当我举起一个手指,它将从触摸 targetTouches 中删除​​,并将显示在 changedTouches 因为它是造成事件的原因

  • 删除我的最后一根手指将离开触及 targetTouches 为空, changedTouches 将包含最后一根手指的信息

  • When I put a finger down, all three lists will have the same information. It will be in changedTouches because putting the finger down is what caused the event
  • When I put a second finger down, touches will have two items, one for each finger. targetTouches will have two items only if the finger was placed in the same node as the first finger. changedTouches will have the information related to the second finger, because it’s what caused the event
  • If I put two fingers down at exactly the same time, it’s possible to have two items in changedTouches, one for each finger
  • If I move my fingers, the only list that will change is changedTouches and will contain information related to as many fingers as have moved (at least one).
  • When I lift a finger, it will be removed from touches, targetTouches and will appear in changedTouches since it’s what caused the event
  • Removing my last finger will leave touches and targetTouches empty, and changedTouches will contain information for the last finger

这篇关于e.touches,e.targetTouches和e.changedTouches的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 12:26