We have talked about TouchSwipe in previously.
- jQuery – Implement touch and gesture based interaction using TouchSwipe
- TouchSwipe – Implement delegated swipe event for inner elements
Unlike TouchSwipe which is a jQuery plugin, hammer.js is independent of jQuery. It supports tap, swipe, drag and other mobile touch events. Here is an simple example.
<!doctype html> <html> <head> <title>Eureka! - hammer.js Example</title> <style type="text/css"> #box { background-color: red; width: 400px; height: 225px; line-height: 225px; text-align: center; } </style> </head> <body> <div id="box">Swipe here!</div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript" src="js/hammer.js"></script> <script type="text/javascript"> var box = document.getElementById("box"); Hammer(box).on("swipeleft", function() { $(this).text("You swiped left" ); }); Hammer(box).on("swiperight", function() { $(this).text("You swiped right" ); }); </script> </body> </html>
If you love using jQuery, you can consider the jQuery version of hammer.js.
Done =)
Reference: GitHub – EightMedia / hammer.js
Reblogged this on Sutoprise Avenue, A SutoCom Source.
LikeLike