Skip to content
项目

关于

用于多点触控手势的 JavaScript 库 :// 触手可及

开发工具

这些数字如何统计

实测星标增长

24小时
-2
7天
-2
15天
-3
1个月
-8

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

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.

探索相关项目

加载中…