I am using phonegap for build android apps.
I would like to detect user's gesture such as a user's swipe. Is there an event i can call from javascript?
Thanks!
One of the most common gestures you will use on your smartphone or tablet is a swipe. That's where you place your finger on the screen and slide it across the surface. In most instances, the item under your finger will move.
Gesture navigation: At the very bottom of the screen, swipe from left to right. 2-button navigation: To switch between your 2 most recent apps, swipe right on Home . 3-button navigation: Tap Overview . Swipe right until you find the app you want.
The swipe event is triggered when the user press down and swipes over an element horizontally by more than 30px (and less than 75px vertically). Tip: You can swipe in both right and left direction. Related events: swipeleft - triggered when the user swipes over an element in the left direction.
android.view.GestureDetector. Detects various gestures and events using the supplied MotionEvent s. The OnGestureListener callback will notify users when a particular motion event has occurred. This class should only be used with MotionEvent s reported via touch (don't use for trackball events).
I use a JavaScript framework called xui (homepage) that has a similar API to jQuery.
You can use this framework coupled with the swipe plugin to get access to easy gesture events. See the swipe/ directory under that repository for the code and example (specifically under index.html). A brief example:
x$('body').swipe(function(e, data) {
console.log('type:' + data.type + ' deltaX:' + data.deltaX + ' deltaY:' + data.deltaY + ' distance:' + data.distance + ' delay:' + data.delay+' direction:' + data.direction );
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With