Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@egjs/hammerjs

naver6.4mMIT2.0.17TypeScript support: included

A javascript library for multi-touch gestures

touch, gestures

readme

hammer.js NPM Version NPM Downloads Build Status

A JavaScript library for detecting touch gestures.

What is this repository?

It seems like that hammer.js repository is no more activated.

But our library (egjs) has deep dependency to hammer.js for touch interaction. And some pending issues were critical for us to make more light size, compatible with node.js , resolve module crash on umd envrioment.

So we solved following issues that are not resolved in original hammer.js

We would maintain this repository to fix remain bugs and enhance it until original repository activates.

Installation

NPM

npm install --save @egjs/hammerjs

or

Yarn

yarn add @egjs/hammerjs

or

CDN

https://cdnjs.com/libraries/hammer.js/

We did not provide CDN yet. leave the link to original hammerjs as is.

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

changelog

Changelog

2.0.8, 2016-04-22

Manager
Input
  • Fixed de-duping of mouse events on mouse touch combo devices (#917, #863, bfeb89a)
Touch-action
  • Added support map for specific values of touch-action (#952, fbe9fd7)

2.0.6, 2015-12-23

  • Add Assign method and deprecate merge and extend (#895fc01eae)
  • Expose Hammer on window or self if either is defined to avoid issues when AMD is present but not used. ( 356f795)
  • Add support for PointerEvent instead of MSPointerEvent if supported. (#754, 439c7a6)
  • Fixed moz-prefix, prefix should be Moz not moz. (3ea47f3)
  • Removed non-existant recognizer (f1c2d3b)
  • Fixed config leaking between instances(189098f)
  • Fixed gaps in gesture configs and update tests to match (70c2902)
  • Fixed Manager off method (#768, da49a27)
  • Added compatibility with requirejs optimizer namespaces ( 70075f2)
  • Made touchaction test zoomable ( 50264a7)
  • Fixed preventing default when for pan-x pan-y case ( 95eaafa)
  • Fixed incorrect touch action pan direction ( a81da57)
  • Fixed combined pan-x pan-y to resolve to none ( fdae07b)
  • Fixed inverted touch-action for pan recognizer (#728, 605bd3b)
  • Fixed dependency on non standard touch list ordering (#610, #791, 287720a)
  • Fixed swipe to not trigger after multitouch gesture (#640, 711d8a1)
  • Fixed swipe recognizer to use overall gesture direction and velocity ( 963fe69)
  • Fixed getDirection returning reversed direction ( e40dcde)
  • Fixed detection of tap when multi touch gestures are present ( c46cbba)
  • Fixed incorrect event order (#824, 92f2d76)
  • Fixed leaking options between recognizer instances (#813, af32c9b)
  • Fixed detection when element has no style attribute ( 5ca6d8c)

2.0.4, 2014-09-28

  • Fix IE pointer issue. #665
  • Fix multi-touch at different elements. #668
  • Added experimental single-user Touch input handler. This to improve performance/ux when only a single user has to be supported. Plans are to release 2.1 with this as default, and a settings to enable the multi-user handler.

2.0.3, 2014-09-10

  • Manager.set improvements.
  • Fix requireFailure() call in Manager.options.recognizers.
  • Make DIRECTION_ALL for pan and swipe gestures less blocking.
  • Fix Swipe recognizer threshold option.
  • Expose the Input classes.
  • Added the option inputClass to set the used input handler.

2.0.2, 2014-07-26

  • Improved mouse and pointer-events input, now able to move outside the window.
  • Added the export name (Hammer) as an argument to the wrapper.
  • Add the option experimental inputTarget to change the element that receives the events.
  • Improved performance when only one touch being active.
  • Fixed the jumping deltaXY bug when going from single to multi-touch.
  • Improved velocity calculations.

2.0.1, 2014-07-15

  • Fix issue when no document.body is available
  • Added pressup event for the press recognizer
  • Removed alternative for Object.create

2.0.0, 2014-07-11

  • Full rewrite of the library.