Hammer.JS With Native jQuery Events

| Comments

If you were looking for a tiny touch event library Hammer.JS does a great job with this. It can be either used with vanilla javascript or as a jQuery extension. It is a definitely a more advanced approach than just grabbing jquery.mobile.vmouse.js and touch.js from the jQuery mobile project.

However Eight Media decided to create their own namespace in jQuery to activate the events.

$("#element").hammer({ /* options */ }).on("tap", function(ev) { console.log(ev); });

So in the end they are not using the default jQuery eventing system. That means my existing source code which used jQuery mobile events has to be change. That’s why I decided to implement the use of Hammer.JS with the jQuery special eventing API.

$("#element").on("tap", { /* options */ }, function(ev) { console.log(ev); });

I put jquery.specialevent.hammer.js onto my Github where you can also find a demo. Maybe Eight Media accepts my pull request and it will be part of Hammer.JS.

Attention: the plugin doesn’t support the jQuery namespacing yet.

Copyright © 2014 - Damien Antipa. Powered by Octopress