hammer.js README

The project's README from github.com/hammerjs/hammer.js. As one markdown file: 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

hammer.js (hammerjs/hammer.js)

Searching Database…

24.3K ·GitHub
这是什么?Hammer.js 是一个 JavaScript 库,能让网页识别触摸手势,这样你就不必自己去解析原始的触摸事件了。
这是要安装到手机上的东西,还是加到网站里的?它是一个前端 JavaScript 库:把它引入网页,网页在哪里运行它就在哪里运行——包括桌面浏览器以及手机、平板这类触摸设备。
怎么把它加到我的项目里?用 npm 或 yarn 安装,或者直接在页面里通过 CDN 引入即可。
它会不会带一堆依赖,把我的项目撑大?不会——这个包运行时零依赖,不会给你的打包文件拖进任何多余的东西。
如果我不需要它认识的手势怎么办,比如三指点按?那得额外下功夫:对于三指点按这类手势,README 说明你必须按照它的步骤自己搭建识别逻辑——它不会白送。
能在商业项目里用吗,要花钱吗?它采用 MIT 许可证,可以免费使用、修改和发布——商业用途也包含在内。
有没有现成的压缩版文件,可以直接放到生产环境用?有——仓库的构建步骤会生成 hammer.min.js 以及对应的 source map,所以你可以直接部署压缩版。
Creator
hammerjs
Size
9.9 MB
Stars
24.3K
Updated
CommitMay 28
Age
14y
Commits · 90 Days