最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Touchmove with Phonegap - Stack Overflow

programmeradmin3浏览0评论

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...

发布评论

评论列表(0)

  1. 暂无评论