A javascript library for multi-touch gestures :// You can touch this
Clone or download
Latest commit 563b5b1 Oct 22, 2017
Permalink
Failed to load latest commit information.
src chore: moves 'defaults' out of the constructor Sep 30, 2016
tests chore(test cleanup): Add missing messages to asserts Sep 30, 2016
.bowerrc add support for component as well as bower Mar 15, 2013
.editorconfig chore: fix styling issues and lints tests Sep 30, 2016
.gitignore hammer 2.0 Jul 11, 2014
.jscsrc chore: fix styling issues and lints tests Sep 30, 2016
.jshintrc chore: fix styling issues and lints tests Sep 30, 2016
.travis.yml chore: saner npm tasks Sep 30, 2016
CHANGELOG.md Changelog: Fix formatting for new markdown processor on jekyll site Apr 23, 2016
CONTRIBUTING.md simulator and jquery plugin in package.json Jul 26, 2014
LICENSE.md Update LICENSE.md Apr 19, 2017
README.md Update README.md Oct 21, 2017
banner.ejs feat(npm scripts): adds npm scripts Sep 30, 2016
bower.json Merge pull request #1013 from anotheredward/patch-1 Oct 19, 2016
changelog.js Changelog: update for 2.0.8 Apr 23, 2016
component.json Build: Prepare 2.0.6 release Dec 24, 2015
hammer.js chore(build): Commiting most recent built files Sep 30, 2016
hammer.min.js chore(build): Commiting most recent built files Sep 30, 2016
hammer.min.js.map chore(build): Commiting most recent built files Sep 30, 2016
hammer.min.map Build: Prepare 2.0.6 release Dec 24, 2015
package.json chore(rollup version): bumps up rollup version Oct 15, 2016
rollup.config.js chore(rollup version): bumps up rollup version Oct 15, 2016
string-replace.js chore: various fixes after rebase. Sep 30, 2016

README.md

hammer.js NPM Version NPM Downloads Build Status

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.

// Get a reference to an element.
var square = document.querySelector('.square');

// Create an instance of Hammer with the reference.
var hammer = new Hammer(square);

// Subscribe to a quick start event: press, tap, or doubletap.
// For a full list of quick start events, read the documentation.
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:

// Get a reference to an element.
var square = document.querySelector('.square');

// Create a manager to manage the element.
var manager = new Hammer.Manager(square);

// Create a recognizer.
var TripleTap = new Hammer.Tap({
  event: 'tripletap',
  taps: 3
});

// Add the recognizer to the manager.
manager.add(TripleTap);

// Subscribe to the event.
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 Github Issues Github PRs Slack

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