12

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!

Dayzza
  • 1,561
  • 7
  • 18
  • 29

2 Answers2

7

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  );
});
gawi
  • 2,843
  • 4
  • 29
  • 44
fil maj
  • 2,260
  • 16
  • 16
  • Thanks mate. this was what i was looking for! sorry for being greedy.. but isit also possible to include to detect custom gesture? such as when a user draw a 'C' or'S'? Thankss! – Dayzza Feb 09 '11 at 03:39
  • with this plugin, unfortunately not. you would have to edit it. After a brief look at the code, it looks like the swipe plugins keeps track of start and end coordinates. For more complex gestures, you'd have to change the code to keep track of several "points" during a gesture (with a short interval timeout, for example), and then compare the coordinates of the various points to conclude something more meaningful about the full gesture after the touchend even fires. hope that helps. – fil maj Feb 09 '11 at 23:26
  • ok sure thanks :D i will look into the codes in detailed.. any idea if i can track the gesture only at a certain area? i.e at the top of the screen..meaning i sort of seperate the screen into half. :D – Dayzza Feb 10 '11 at 04:37
  • there is another library, also called jGestures, which is designed specifically for custom gestures - you define the shapes and it will tell you when the user does something similar to one of the shapes. see here: http://stanford.wikia.com/wiki/CS349W_Project3_jGestures – mmaclaurin Jun 27 '12 at 20:40
3

jQuery Mobile also provides basic support for gestures (at least tap, long tap and swipe left&right).

Some additional plugins can be found on the Resources site. Maybe there are more of them on the plugin site.

Ignitor
  • 2,907
  • 33
  • 50