A JavaScript library for detecting touch gestures.
Installation
NPM
npm install --save hammerjs
or
Yarn
yarn add hammerjs
or
CDN
https://cdnjs.com/libraries/hammer.js/
Usage
hammer.js has a quick start option for gestures it already recognizes.
var square = document.querySelector('.square');
var hammer = new Hammer(square);
hammer.on('press', function(e) {
e.target.classList.toggle('expand');
console.log("You're pressing me!");
console.log(e);
});
If you want to recognize your own gestures, such as tripletap
, then you'll have to use these steps:
var square = document.querySelector('.square');
var manager = new Hammer.Manager(square);
var TripleTap = new Hammer.Tap({
event: 'tripletap',
taps: 3
});
manager.add(TripleTap);
manager.on('tripletap', function(e) {
e.target.classList.toggle('expand');
console.log("You're triple tapping me!");
console.log(e);
});
Examples
Documentation
For further information regarding hammer.js, please read our documentation.
Contributions
![Slack](https://hammerjs.herokuapp.com/badge.svg)
Feel encouraged to report issues or submit pull requests. When you're ready to do either, read our contribution guidelines. If you're looking for another form of contribution, we love help answering questions on our slack channel.
License
MIT