Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you bind a touch function with Zepto properly?

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
like image 778
CSturgess Avatar asked Dec 02 '25 13:12

CSturgess


1 Answers

Instead of

e.data.x1

You need to use

e.touches[0].pageX
like image 130
CSturgess Avatar answered Dec 04 '25 01:12

CSturgess



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!