Javascript e.touches、e.targetTouches 和 e.changedTouches 的变化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7056026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Variation of e.touches, e.targetTouches and e.changedTouches
提问by Andrei Zisu
Let's say I am listening for touchstart, touchmoveand touchendon the bodyelement.
比方说,我正在听的touchstart,touchmove和touchend在上body的元素。
Let me know if I'm wrong, but I think e.touchesis the same as e.targetTouches? If so, how e.changedTouchesvaries in relation with them?
如果我错了,请告诉我,但我认为e.touches与e.targetTouches? 如果是这样,e.changedTouches它们之间的关系如何变化?
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?
我必须将解析后的数据发送到服务器,发送三倍相同的字符串是非常多余的,有没有办法将它们发送一次并以编程方式在服务器上重现触摸事件?
回答by Andrei Zisu
We have the following lists:
我们有以下清单:
touches: A list of information for every finger currently touching the screentargetTouches: Like touches, but is filtered to only the information for finger touches that started out within the same nodechangedTouches: A list of information for every finger involved in the event
touches:当前触摸屏幕的每个手指的信息列表targetTouches: 像触摸一样,但被过滤到只有在同一节点内开始的手指触摸的信息changedTouches:事件中涉及的每个手指的信息列表
To better understand what might be in these lists, let's go over some examples quickly. They vary according to the following rules:
为了更好地理解这些列表中可能包含的内容,让我们快速浏览一些示例。它们根据以下规则变化:
- When I put a finger down, all three lists will have the same information. It will be in
changedTouchesbecause putting the finger down is what caused the event - When I put a second finger down,
toucheswill have two items, one for each finger.targetToucheswill have two items only if the finger was placed in the same node as the first finger.changedToucheswill 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
changedTouchesand 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,targetTouchesand will appear inchangedTouchessince it's what caused the event - Removing my last finger will leave
touchesandtargetTouchesempty, andchangedToucheswill contain information for the last finger
- 当我放下手指时,所有三个列表都将具有相同的信息。它会在,
changedTouches因为放下手指是导致事件的原因 - 当我放下第二根手指时,
touches将有两个项目,每个手指一个。targetTouches只有当手指与第一个手指放在同一节点时才会有两个项目。changedTouches将有与第二根手指相关的信息,因为它是导致事件的原因 - 如果我同时放下两根手指,则可能有两个项目
changedTouches,每个手指一个 - 如果我移动手指,唯一会改变的列表
changedTouches将包含与移动的手指(至少一个)相关的信息。 - 当我抬起一根手指时,它会从 中移除
touches,targetTouches并且会出现在,changedTouches因为它是导致事件的原因 - 删除我的最后一根手指将离开
touches并为targetTouches空,changedTouches并将包含最后一根手指的信息

