Detect user's gesture such as swipe

Dayzza picture Dayzza · Feb 7, 2011 · Viewed 20.7k times · Source

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!

Answer

fil maj picture fil maj · Feb 7, 2011

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  );
});