Touch Anywhere (on the screen) You Want With Hammer.js and BlackBerry 10 WebWorks

Web Development

With the launch of BlackBerry 10 and all touch devices ready to rock and roll, you may be interested in adding touch or multi-touch gestures in to your BlackBerry WebWorks apps.

I came across an amazing JavaScript library called Hammer.js which makes it super easy to incorporate gestures into your application with only a few lines of code. The library is extremely lightweight, running ~2KB minified, and handles all of the legwork for you.

Hammer.js supports quite a few gestures too:

  • Tap
  • Double Tap
  • Hold
  • Swipe
  • Drag
  • Transform (Pinching)

Of course, what would touch events be without the actual Event data? When a user interacts with the screen, Hammer.js reports back to you with all of the information related to the touch. You can find out how long somebody touched the screen, where they touched, which direction they were swiping or dragging, the momentum of the swipe, and so on

So, why would you want use Hammer.js in your projects?

It’s lightweight

Sure, there are other libraries out there that handle gestures, but it’s important to think about resources when creating mobile apps. Hammer.js runs about 2kb (minified) and leaves a very tiny footprint.

Simple to use

The syntax is incredibly easy to both use and understand. There’s even a jQuery plugin available if you’re like me and like to take shortcuts in your code.

Plays nice with others

Hammer.js works well alongside other libraries and frameworks. Whether you’re using jQuery, bbUI.js, Backbone.js, or others, you should have no worries that Hammer.js will interfere. It performs very well, and doesn’t get in the way.

Check out my sample app!

I worked very hard for what seemed like minutes, creating an awesome sample app to show how easy it is to use the Hammer.js library. Check it out in our GitHub repo – there’s even a special appearance by the one-and-only Jesse Ariss!

If you have any questions, or comments, feel free to hit me up on Twitter. I like the attention. @chadtatro

About Chad Tetreault

Developer Relations at BlackBerry. Team @FilterMama and @TacoQuestApp member. #HTML5. I code in DOS Edit. BBM Channel C00124CF8

Join the conversation

Show comments Hide comments
+ -
blog comments powered by Disqus