Hammer.js is a JavaScript library that can be used to control gestures on touch devices. It supports the following gestures:
Place hammer.js in your web document like so:
<script src="http://eightmedia.github.com/hammer.js/hammer.js"></script<
Hammertime! Bind hammer to a container element:
var hammer = new Hammer(document.getElementById("container"));
Now, on every gesture that is performed on the container element, you'll receive a callback object with information on the gesture.
hammer.ondragstart = function(ev) { };
hammer.ondrag = function(ev) { };
hammer.ondragend = function(ev) { };
hammer.ontap = function(ev) { };
hammer.ondoubletap = function(ev) { };
hammer.onhold = function(ev) { };
hammer.ontransformstart = function(ev) { };
hammer.ontransform = function(ev) { };
hammer.ontransformend = function(ev) { };
The hammer.js jQuery plugin is implemented like so:
<script src="http://eightmedia.github.com/hammer.js/jquery.hammer.js"></script<
<script>
$("#element")
.hammer({
// options...
})
.bind("tap", function(ev) {
console.log(ev);
});
</script>