javascript 使用 PhoneGap 在 Android 和 iPhone 上的“touchmove”事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14925925/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"touchmove" event on Android &iPhone using PhoneGap
提问by Petar Vasilev
so basically I want to be able to get the coordinates of the touch when someone swipes across the screen of a touch-enable device powered by iOS or Android.
所以基本上我希望能够在有人在由 iOS 或 Android 驱动的支持触摸的设备的屏幕上滑动时获得触摸的坐标。
What I've tried to do so far is as follows.
到目前为止我尝试做的如下。
$('element').bind("touchmove", function(e) {
$(element2).html(e.pageX + "," + e.pageY);
}
plus I've tried the same with "vmousemove"(the jquery mobile equivalent or so it should be), "mousemove" but to no avail. I only get the coordinates of the the initial and end touch.
另外,我已经尝试过同样的“vmousemove”(jquery mobile 等价物,应该是这样),“mousemove”,但无济于事。我只得到初始和结束触摸的坐标。
Thanks in advance
提前致谢
回答by Vlad Stirbu
iOS and Android are muti-touch devices. The interaction is handled using touch events:
iOS 和 Android 是多点触控设备。交互是使用触摸事件处理的:
回答by davewasthere
You're very close... All you needed was the original Event. jQuery wraps these up for you.
你非常接近......你所需要的只是原始事件。jQuery 为您包装了这些。
e.g.
例如
$('element').bind("touchmove", function(event) {
var e = ev.originalEvent;
var touch = e.touches[0];
$(element2).html(touch.pageX + "," + touch.pageY);
}
EDIT: I forgot about the touches array... my bad.
编辑:我忘记了触摸阵列......我的错。