Activate your free membership today | Log-in

Monday, December 22nd, 2008

jQuery Gestures

Category: JavaScript, Library, jQuery

Adrien Friggeri has taken the music player ui and spent some time to create a really nice gestures library that allows you to add mouse gestures to a web page, supports complex (i.e. sequences of) gestures and provides visual feedback through the use of a canvas element.

Example code looks like this:

JAVASCRIPT:
  1.  
  2. // initialize the engine, inactive by default and set the trace color to red
  3. $.gestures.init({active:false,color:'#ff0000'});
  4.  
  5. // adds a new gesture : Down
  6. $.gestures.register('D', function() {
  7.   alert('down !');
  8.   });
  9.  
  10. // a more complex gesture : Down, Left, Up, Right
  11. $.gestures.register('DLUR', function() {
  12.   alert('this is a rectangle, no ?');
  13.   });
  14.  
  15. // you can log unknown gestures :
  16. $.gestures.error(function(gesture) {
  17.   alert("oops, I don't understand what \""+gesture+"\" means");
  18. });
  19.  
  20. // useful keyboard tricks :
  21. $(window).keydown(function(e) {
  22.   if ($.gestures.active() && e.which==27) {
  23.     // disable capture when user presses ESC
  24.     $.gestures.disable();
  25.   } else if (!$.gestures.active() && e.which==17) {
  26.     // enable capture when CTRL is pressed
  27.     $.gestures.enable();
  28.   }
  29. });
  30. $(window).keyup(function(e) {
  31.   // disable capture when CTRL is not pressed
  32.   if ($.gestures.active() && e.which==17) {
  33.   $.gestures.disable();
  34.   }
  35. });
  36.  

Posted by Dion Almaer at 8:28 am
11 Comments

++++-
4 rating from 34 votes

11 Comments »

Comments feed TrackBack URI

No links?

Comment by JimNeath — December 22, 2008

http://random.friggeri.net/jquery-gestures/

Comment by Spir — December 22, 2008

lol!

Comment by sidonaldson — December 22, 2008

This is a general comment: Please, Please, add links to the original article, site, blog or product. Even if you just mention someone/something, a link would be nice.

Comment by mvcoile — December 22, 2008

Please always add a link to the article. Some of these things are useful.

Comment by cssProdigy — December 22, 2008

Not sure when I would use it, but its pretty damn cool. Also – a really good use of canvas.

Comment by genericallyloud — December 22, 2008

Actually, the original blog article is here :
http://friggeri.net/blog/2008/12/21/jquery-gestures

Comment by AdrienFriggeri — December 22, 2008

To all concerned about the link not being included, it was an oversight. Posts on Ajaxian typically include many links but sometimes it slips through the cracks.

Comment by Rey Bango — December 22, 2008

I’m not a fan of gestures per-se, but I know a lot of people that would love it, so I’ve given this a 5.

Comment by oopstudios — December 22, 2008

I turned on gestures in GMail (labs) and rarely use them. My hand always tracks to the buttons/links out of habit before I realize I could have just swiped right or left. For something like a photo gallery, where there is quick scrolling or browsing, this could be very useful.

Comment by Jigs — December 22, 2008

Fitch store in general Abercrombie And Fitch , everything a good matrimony before marriage have nothing to retain the preceding “female mad batch -Abercrombie” part of the two is the first home in new york city a horde promotion sportswear for men and it is a successful lawyer, that is, fitch.Ezra fitch in a charge over a very intricate to read from the abercrombie is obstinate to read and long abercrombie & fitch. He’s also very good brandAbercrombie Clothing, including Abercrombie Sale and Abercrombie And Fitch Clothing, Abercrombie and Fitch Hoodies, Abercrombie and Fitch Jeans. Has become a fashionable personage’s first choice,Abercrombie and Fitch Pants is all over the world, of course, is also expected toAbercrombie and Fitch Tees.
New Year was coming, everyone wants new clothes to disguise themselves,Abercrombie and Fitch Shorts is a good choice. BecauseAbercrombie and Fitch Sweaters is a well-known brand,Abercrombie and Fitch Outerweareverywhere, abercrombie is very much a Cheap Abercrombie. There has Abercrombie and Fitch Polos, Abercrombie Womens andAbercrombie and Fitch Shirt. Personally, I’m looking forward to Abercrombie Hollister’s 2009 New Arrivals, such as Abercrombie Ruehl No.925 like this style.
Fitch store in general Abercrombie And Fitch , everything a good matrimony before marriage have nothing to retain the preceding “female mad batch -Abercrombie” part of the two is the first home in new york city a horde promotion sportswear for men and it is a successful lawyer, that is, fitch.Ezra fitch in a charge over a very intricate to read from the abercrombie is obstinate to read and long abercrombie & fitch. He’s also very good brandAbercrombie Clothing, including Abercrombie Sale and Abercrombie And Fitch Clothing, Abercrombie and Fitch Hoodies,Abercrombie and Fitch Jeans. Has become a fashionable personage’s first choice,Abercrombie and Fitch Pants is all over the world, of course, is also expected toAbercrombie and Fitch Tees.
New Year was coming, everyone wants new clothes to disguise themselves,Abercrombie and Fitch Shorts is a good choice. BecauseAbercrombie and Fitch Sweatersis a well-known brand,Abercrombie and Fitch Outerwear everywhere, abercrombie is very much a Cheap Abercrombie. There has Abercrombie and Fitch Polos, Abercrombie Womens andAbercrombie and Fitch Shirt. Personally, I’m looking forward to Abercrombie Hollister’s 2009 New Arrivals, such as Abercrombie Ruehl No.925 like this style.

Lace Wigs
Wedding Dresses
ugg boots

Comment by CYJisGod — March 4, 2010

Leave a comment

You must be logged in to post a comment.