Skip to content
hammerjsPublic

About

A javascript library for multi-touch gestures :// You can touch this

Resources

Contributing

Stars

24.3k stars

Watchers

493 watching

Forks

Repository files navigation

Hammer.js

CI npm version

A JavaScript library for multi-touch gestures.

Visit hammerjs.github.io for detailed documentation.

Installation

npm install hammerjs

Or download the pre-built bundle from GitHub Releases or load it from a CDN:

<script src="https://cdn.jsdelivr.net/npm/hammerjs/hammer.min.js"></script>

Usage

Create a Hammer instance on a DOM element to listen for the default gestures (pan, swipe, tap, doubletap, and press):

import Hammer from 'hammerjs';

const element = document.getElementById('my-element');
const mc = new Hammer(element);

mc.on('panleft panright tap press', (ev) => {
    console.log(ev.type + ' gesture detected.');
});

For full control over recognizers and how they interact (such as simultaneous gestures or requiring another gesture to fail), use Hammer.Manager:

const mc = new Hammer.Manager(element);

mc.add(new Hammer.Pan({ direction: Hammer.DIRECTION_ALL, threshold: 0 }));
mc.add(new Hammer.Tap({ event: 'doubletap', taps: 2 }));
mc.add(new Hammer.Tap());

mc.get('doubletap').recognizeWith('tap');
mc.get('tap').requireFailure('doubletap');

mc.on('doubletap', (ev) => {
    console.log('doubletap', ev);
});

mc.on('tap', (ev) => {
    console.log('tap', ev);
});

Building & Testing

Requires Node.js >= 22.

npm install
npm test       # runs ESLint and the QUnit suite in headless Chrome
npm run lint   # runs ESLint only
npm run build  # builds hammer.js, hammer.min.js, sourcemaps, and runs tests

Contributing

Read the contributing guidelines before opening an issue or pull request.

For pull requests:

  • Use Angular-style commit messages
  • Make changes in src/ and tests/ (do not commit rebuilt hammer.js / hammer.min.js bundles)
  • Add or update unit tests for any bug fix or behavior change
  • Run npm test to verify linting and all unit tests pass

For maintainers cutting a release, see RELEASING.md.

License

Licensed under the MIT License.

About

A javascript library for multi-touch gestures :// You can touch this

Resources

Contributing

Stars

24.3k stars

Watchers

493 watching

Forks

Releases

Packages

Used by

Contributors

Languages