Javascript – Implement touch and gesture based interaction using hammer.js

We have talked about TouchSwipe in previously.


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>
  <title>Eureka! - hammer.js Example</title>
  <style type="text/css">
    #box {
      background-color: red;
      width: 400px;
      height: 225px;
      line-height: 225px;
      text-align: center;
  <div id="box">Swipe here!</div>
  <script src=""></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" );


If you love using jQuery, you can consider the jQuery version of hammer.js.


Done =)

Reference: GitHub – EightMedia / hammer.js


One thought on “Javascript – Implement touch and gesture based interaction using hammer.js”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.