Touchmove with Phonegap

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?

Answers:

Answer

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

https://developer.apple.com/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...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.