3

I'm trying to bind an event to the touchstart, touchmove, and touchend properties that will track the location of the touch. Here's my code:

$('#container').bind('touchstart touchmove touchend', function (event) { updateFinger(event); });

And the update finger function:

var updateFinger = function(e)
{
  e.preventDefault();
  fingerX = e.data.x1;
  fingerY = e.data.y1;
  alert(fingerX + ' ' + fingerY);
}

I know the function is called, but from what I can tell, e.data.x1 and e.data.y1 don't exist (As well as .x). I'm using the code in the documentation, can anyone help me out with this?

EDIT: I fixed the problem, it turns out I was using the wrong code.

Instead of

e.data.x1

You need to use

e.touches[0].pageX
1
  • 1
    That's great. Could you create an answer for that and mark it as accepted. This way, your question will move out of the "unanswered" lists.
    – swatkins
    Commented Jan 16, 2012 at 20:36

1 Answer 1

7

Instead of

e.data.x1

You need to use

e.touches[0].pageX

Not the answer you're looking for? Browse other questions tagged or ask your own question.