Hammer.js

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

README

[hammer.js][hammerjs-url]  [![NPM Version][npm-image]][npm-url]  [![NPM Downloads][downloads-image]][downloads-url]  [![Build Status][travis-image]][travis-url]

A JavaScript library for detecting touch gestures.



Installation

NPM

  1. ```sh
  2. npm install --save hammerjs
  3. ```

or

Yarn

  1. ```sh
  2. yarn add hammerjs
  3. ```

or

CDN



Usage

hammer.js has a quick start option for gestures it already recognizes.
  1. ``` js
  2. // Get a reference to an element.
  3. var square = document.querySelector('.square');

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

  6. // Subscribe to a quick start event: press, tap, or doubletap.
  7. // For a full list of quick start events, read the documentation.
  8. hammer.on('press', function(e) {
  9.   e.target.classList.toggle('expand');
  10.   console.log("You're pressing me!");
  11.   console.log(e);
  12. });
  13. ```

If you want to recognize your own gestures, such as tripletap, then you'll have to use these steps:
  1. ``` js
  2. // Get a reference to an element.
  3. var square = document.querySelector('.square');

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

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

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

  13. // Subscribe to the event.
  14. manager.on('tripletap', function(e) {
  15.   e.target.classList.toggle('expand');
  16.   console.log("You're triple tapping me!");
  17.   console.log(e);
  18. });
  19. ```


Examples

- [tap][tap]
- [double tap][double-tap]
- [press][press]
- [swipe][swipe]


Documentation

For further information regarding hammer.js, please read our [documentation][hammerjs-url].


Contributions  [![Github Issues][issues-image]][issues-url]  [![Github PRs][pulls-image]][pulls-url]  [![Slack][slack-image]][slack-url]

Feel encouraged to report issues or submit pull requests. When you're ready to do either, read our [contribution guidelines][contribution-guidelines]. If you're looking for another form of contribution, we love help answering questions on our [slack channel][slack-url].


License

[MIT][license]

[hammerjs-url]: http://hammerjs.github.io

[npm-image]: https://img.shields.io/npm/v/hammerjs.svg
[npm-url]: https://npmjs.org/package/hammerjs

[travis-image]: https://img.shields.io/travis/stream-utils/raw-body/master.svg
[travis-url]: https://travis-ci.org/hammerjs/hammer.js

[downloads-image]: https://img.shields.io/npm/dm/hammerjs.svg
[downloads-url]: https://npmjs.org/package/hammerjs



[tap]: https://codepen.io/choskim/pen/WZggmg
[double-tap]: https://codepen.io/choskim/pen/vezzwZ
[press]: https://codepen.io/choskim/pen/RLYebL
[pan]: ''
[swipe]: https://codepen.io/choskim/pen/rGZqxa
[pinch]: ''
[rotate]: ''



[issues-image]: https://img.shields.io/github/issues/hammerjs/hammer.js.svg
[issues-url]: https://github.com/hammerjs/hammer.js/issues

[pulls-image]: https://img.shields.io/github/issues-pr/hammerjs/hammer.js.svg
[pulls-url]: https://github.com/hammerjs/hammer.js/pulls

[slack-image]: https://hammerjs.herokuapp.com/badge.svg
[slack-url]: https://hammerjs.herokuapp.com/

[contribution-guidelines]: ./CONTRIBUTING.md

[license]: ./LICENSE.md