Skip to content
Projets

À propos

Bibliothèque JavaScript pour les gestes multipoints :// You can touch this

Outils de développement

Comment ces chiffres sont mesurés

Progression mesurée des étoiles

in 24h
-2
in 7 days
-2
in 15 days
-3
in 1 month
-8

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

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.

Explorer des projets similaires

Chargement…