1

so basically I want to be able to get the coordinates of the touch when someone swipes across the screen of a touch-enable device powered by iOS or Android.

What I've tried to do so far is as follows.

$('element').bind("touchmove", function(e) {
    $(element2).html(e.pageX + "," + e.pageY);
}

plus I've tried the same with "vmousemove"(the jquery mobile equivalent or so it should be), "mousemove" but to no avail. I only get the coordinates of the the initial and end touch.

Thanks in advance

Petar Vasilev
  • 4,281
  • 5
  • 40
  • 74

2 Answers2

6

iOS and Android are muti-touch devices. The interaction is handled using touch events:

https://developer.mozilla.org/en-US/docs/DOM/Touch_events

Vlad Stirbu
  • 1,732
  • 2
  • 16
  • 27
  • Precisely, I've tried using "touchmove" but the callback function is called only twice.... I am using phonegap 2.3.0 and this happens on Android 4.0.1 – Petar Vasilev Feb 18 '13 at 20:23
  • 2
    Yes, but you don't handle the event e correctly. You should work with e.touches. It provides an array of Touch objects.See also this: http://developer.apple.com/library/safari/#documentation/UserExperience/Reference/TouchEventClassReference/TouchEvent/TouchEvent.html – Vlad Stirbu Feb 18 '13 at 20:46
0

You're very close... All you needed was the original Event. jQuery wraps these up for you.

e.g.

$('element').bind("touchmove", function(event) {
   var e = ev.originalEvent;
   var touch = e.touches[0];
   $(element2).html(touch.pageX + "," + touch.pageY);
}

EDIT: I forgot about the touches array... my bad.

davewasthere
  • 2,988
  • 2
  • 24
  • 25