Tuesday, May 21, 2024
 Popular · Latest · Hot · Upcoming
48
rated 0 times [  53] [ 5]  / answers: 1 / hits: 52514  / 13 Years ago, thu, august 25, 2011, 12:00:00

If I catch all touchend events from mobile devices with:



$(document.body).bind('touchend', function (e) {
var touch = e.touches[0]; // doesnt work
...


I need to get the touch.screenX, touch.screenY, touch.clientX and touch.clientX from the e paramter. All the examples I've seen suggest that e.touches will be a collection, and you can get at the touch details with e.touches[0]. In my tests on an ipad, e.touches is always undefined. I'm not using any jquery plugins.



Also tried e.targetTouches, which is also undefined.



Can anyone help?


More From » jquery

 Answers
17

Actually, released touches will be found in the changedTouches array, ie:



e.changedTouches[0].pageX // get the end x page coordinate for a released touch



I think this is slightly more reliable than going through the originalEvent property.



You can read more on changedTouches here:
http://www.w3.org/TR/touch-events/#changedtouches-of-a-touchevent


[#90415] Wednesday, August 24, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
karolinab

Total Points: 644
Total Questions: 98
Total Answers: 117

Location: Vanuatu
Member since Mon, Dec 7, 2020
4 Years ago
;