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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:31:59  来源:igfitidea点击:

phonegap: is it possible to detect swipeLeft and SwipeRight touch from Javascript?

javascriptandroidcordova

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

在移动浏览器的触摸事件包括touchstarttouchendtouchmove,等。

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, touchendevents etc.

但是您可以通过将 javascript 与 stock touchstarttouchendevents 等结合使用来模拟那些更复杂的事件。

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 swipeleftand swiperightevents, as well as others.

我自己,我倾向于使用 jQuery Mobile,它有swipeleftswiperight事件,以及其他。

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

We use quo.js. It`s a lightweight framework to handle multi touch events and more.

我们使用quo.js。它是一个处理多点触控事件等的轻量级框架。

回答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