phonegap:是否可以从 Javascript 中检测到 swipeLeft 和 SwipeRight 触摸?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13701026/
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
phonegap: is it possible to detect swipeLeft and SwipeRight touch from Javascript?
提问by Gaurav
I ask if a Phonegap application is able to recognize swipeLeft and SwipeRight related events in Javascript.
我问 Phonegap 应用程序是否能够识别 Javascript 中与 swipeLeft 和 SwipeRight 相关的事件。
回答by asgeo1
Phonegap doesn't give you anymore touch events than you otherwise get with a normal mobile website. I.e. it's just wrapping a UIWebView (on iOS) or whatever the equivalent is on the other platforms.
与普通移动网站相比,Phonegap 不会为您提供更多的触摸事件。即它只是包装一个 UIWebView(在 iOS 上)或其他平台上的任何等价物。
Touch events in mobile browsers include touchstart
, touchend
, touchmove
, etc.
在移动浏览器的触摸事件包括touchstart
,touchend
,touchmove
,等。
There aren't any fancy swipe events, or double-tap events, or anything like that natively implemented in mobile browsers.
没有任何花哨的滑动事件,或双击事件,或在移动浏览器中原生实现的类似事件。
But you can simulate those more complicated events by using javascript in conjunction with the stock touchstart
, touchend
events etc.
但是您可以通过将 javascript 与 stock touchstart
、touchend
events 等结合使用来模拟那些更复杂的事件。
Luckily you don't need to bother writing those events yourself because nearly every mobile framework has done that for you. Other people have mentioned some libraries that handle touch events.
幸运的是,您不需要自己编写这些事件,因为几乎每个移动框架都为您完成了这些。其他人提到了一些处理触摸事件的库。
Myself, I tend to use jQuery Mobile which has swipeleft
and swiperight
events, as well as others.
我自己,我倾向于使用 jQuery Mobile,它有swipeleft
和swiperight
事件,以及其他。
http://jquerymobile.com/demos/1.2.0/docs/api/events.html
http://jquerymobile.com/demos/1.2.0/docs/api/events.html
You don't even have to use the full jQuery Mobile framework if you don't want to. You can just include their touch event handlers if you want.
如果您不想,您甚至不必使用完整的 jQuery Mobile 框架。如果需要,您可以只包含他们的触摸事件处理程序。
回答by u635504
回答by Ved
Use thisone its working in ios and android with phonegap.
使用这一个在其工作的ios和android与PhoneGap的。
$("#test").swipe( {
click:function(event, target) {
log("click from callback");
},
swipe:function(event, direction, distance, duration, fingerCount) {
log("swipe from callback");
},
swipeLeft:function(event, distance, duration, fingerCount) {
log("swipeLeft from callback");
},
swipeRight:function(event, distance, duration, fingerCount) {
log("swipeRight from callback");
},
swipeUp:function(event, distance, duration, fingerCount) {
log("swipeUp from callback");
},
swipeDown:function(event, distance, duration, fingerCount) {
log("swipeDown from callback");
},
swipeStatus:function(event, phase, direction, distance, duration, fingers) {
log("swipeStatus from callback");
},
pinchIn:function(event, direction, distance, duration, fingerCount, pinchZoom) {
log("pinchIn from callback");
},
pinchOut:function(event, direction, distance, duration, fingerCount, pinchZoom) {
log("pinchOut from callback");
},
pinchStatus:function(event, phase, direction, distance , duration , fingerCount, pinchZoom) {
log("pinchStatus from callback");
},
fingers:$.fn.swipe.fingers.ALL
});
回答by rinkesh
Excellent jquery Plugin TouchSwipe-Jquery-Pluginfor swipe features
优秀的 jquery 插件TouchSwipe-Jquery-Pluginfor swipe features
回答by olore
Zepto has touch events for swipeLeft and swipeRight, and many others: http://zeptojs.com/#Touch%20events
的Zepto有swipeLeft和swipeRight触摸事件,和其他许多人:http://zeptojs.com/#Touch%20events