admin管理员组

文章数量:1389897

I'm really struggling on an Android app in Phonegap and JQuery.

All I want to do is bind a touchmove to an element and then check the X and Y coordinates as I move my finger (a drag, basically)

$('#someElm').bind('touchmove',function(event){
        //Code here..!
});

The touchmove fires when I touch the screen, but then I don't really know what the objects of the event are - I've tried event.screenX, event.pageX, but the don't work.

Any ideas?

I'm really struggling on an Android app in Phonegap and JQuery.

All I want to do is bind a touchmove to an element and then check the X and Y coordinates as I move my finger (a drag, basically)

$('#someElm').bind('touchmove',function(event){
        //Code here..!
});

The touchmove fires when I touch the screen, but then I don't really know what the objects of the event are - I've tried event.screenX, event.pageX, but the don't work.

Any ideas?

Share Improve this question edited Nov 7, 2011 at 22:46 Daniel Kurka 7,9732 gold badges26 silver badges43 bronze badges asked Nov 7, 2011 at 22:32 ojsglobalojsglobal 5341 gold badge8 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Here the reference for mobile safari (android is basically the same):

https://developer.apple./library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html

what you want is:

var x = event.touches[0].pageX;
var y = event.touches[0].pageY;

If you are running on android you also need to cancel the touchmove event to get new ones while touching. Don't ask me why...

本文标签: javascriptTouchmove with PhonegapStack Overflow