24 March 2014

Capturing mouse coordinates on touchmove events

I'm testing a relatively recent version of Android, iOS, and Chrome to capture mouse coordinates during a move event. I was having trouble with Android, surprisingly, and found this to solve it:

on Chrome and iOS off the jquery event object passed to the touchmove event listener, simply event.pageX and event.pageY returned coordinates as expected. However, Android always returned zero.

You can find a bunch of posts about needing to preventDefault to get the touchmove event to trigger in the first place....

But to get the coordinates, this object seems to work:

window.event.touches[0]

 So I'm using something along these lines ...

if (window.event.touches) event = window.event.touches[0];

Then I use event.pageX and event.pageY as expected...

No comments: