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
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
Share
Improve this question
edited Aug 20, 2012 at 3:20
wprl
25.5k11 gold badges57 silver badges70 bronze badges
asked Jan 13, 2012 at 15:02
CSturgessCSturgess
1,5572 gold badges13 silver badges29 bronze badges
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
Reset to default 7Instead of
e.data.x1
You need to use
e.touches[0].pageX