Questions tagged [hammer.js]

Hammer is an open-source library that can recognize gestures made by touch, mouse and pointerEvents. It has support for multiple instances the same time, so you can start creating multi-user touch interfaces.

Hammer is a open-source library that can recognize gestures made by touch, mouse and pointerEvents. It has support for multiple instances the same time, so you can start creating multi-user touch interfaces. Hammer doesn't have any dependencies, and it's small, only 3.7 kB minified + gzipped!

Visit the website: http://hammerjs.github.io/

Usage

It's easy to use, just include the library and create a new instance. js var hammertime = new Hammer(element, options); hammertime.on('pan', function(ev) { console.log(ev); });

By default it adds a set of tap, doubletap, press, horizontal pan and swipe, and the multi-touch pinch and rotate recognizers. The pinch and rotate recognizers are disabled by default because they would make the element blocking, but you can enable them by calling js mc.get('pinch').set({ enable: true }); mc.get('rotate').set({ enable: true });

Also the viewport meta tag is recommended, it gives more control back to the webpage by disabling the doubletap/pinch zoom. More recent browsers that support the touch-action property don't require this. html <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">

More control

You can setup your own set of recognizers for your instance. This requires a bit more code, but it gives you more control about the gestures that are being recognized. js var myOptions = { }; var mc = new Hammer.Manager(myElement, myOptions); mc.add(new Hammer.Pan({ direction: Hammer.DIRECTION_ALL, threshold: 0 })); mc.add(new Hammer.Tap({ event: 'quadrupletap', taps: 4 })); mc.on("pan", handlePan); mc.on("quadrupletap", handleTaps); The example above creates an instance containing a pan and a quadrupletap gesture. The recognizer instances you create a being executed in the order they are added, and only one can be recognized at the time.

See the pages about the recognizeWith and requireFailure for more details.

Notes

It's recommended to listen to this loop while using hammer.js. Follow @jorikdelaporik for tweets about this library.

Special thanks to Pepe Cano for his contributions.

747 questions
277
votes
9 answers

Consider marking event handler as 'passive' to make the page more responsive

I am using hammer for dragging and it is getting choppy when loading other stuff, as this warning message is telling me. Handling of 'touchstart' input event was delayed for X ms due to main thread being busy. Consider marking event handler as…
Matt
  • 33,328
  • 25
  • 83
  • 97
105
votes
10 answers

Angular - 'Could not find HammerJS'

I'm working on a simple angular project where I am trying to import Material Design into my project but some of the components aren't working properly and a console warning says: Could not find HammerJS. Certain Angular Material components may not…
Danoram
  • 8,132
  • 12
  • 51
  • 71
62
votes
5 answers

Could not find HammerJS in angular 6

I use angular-material in my project. I am getting this warnings: Could not find HammerJS. Certain Angular Material components may not work correctly. The "longpress" event cannot be bound because Hammer.JS is not loaded and no custom loader has…
PGH
  • 2,164
  • 9
  • 34
  • 62
41
votes
5 answers

Pinch to zoom using Hammer.js

I am trying to implement pinch to zoom using hammer.js Here's my HTML-
nickalchemist
  • 2,211
  • 6
  • 31
  • 58
33
votes
5 answers

Vertical scroll is not working with HammerJS and Angular2

I'm having a problem using the HammerJS with Angular2. I have a carousel (based on the bootstrap carousel with Angular2 event handlers) where I'm listening to the swipe left and swipe right events. The swipe itself works perfectly. The problem is…
user1511408
  • 445
  • 1
  • 4
  • 9
32
votes
4 answers

How to use Hammer to swipe

I've found an interesting resource: Hammer.js. I tried to swipe with Hammer and jQuery. 1) I've downloaded the code here 2) I've put that code in a document. I put a link to that code in the head of the document I want to use swipe:
Nrc
  • 9,577
  • 17
  • 67
  • 114
26
votes
2 answers

Mobile Safari crashes when using Hammer.js

I am working on a multi-player game in Javascript for the iPad. I am using Smartfox Server for the multiplayer, and Hammer.js for touch events. I am having an issue where when I use a Hammer event in one particular part of my game, it crashes…
user3203339
  • 261
  • 2
  • 3
16
votes
2 answers

hammer.js object has no method addEventListener

I am getting the Error: Uncaught TypeError: Object [object Object] has no method 'addEventListener' hammer.js:168 my code is like this: On device ready function: var resim =…
hdayi
  • 423
  • 2
  • 4
  • 13
15
votes
1 answer

Angular: when update from 8 to 9 - hammerjs + @angular/platform-browser stopped working

I'm using hammerjs for detecting swipe on a small Angular 8 app. I followed this article - https://medium.com/angular-in-depth/gestures-in-an-angular-application-dde71804c0d0 - and I'm using hammerjs with @angular/platform-browser. However, when 3…
pesho hristov
  • 1,946
  • 1
  • 25
  • 43
13
votes
1 answer

App won't recognize swipes using Hammer.JS and HammerGestureConfig in Angular 9

I can't recognize swipes in my Angular app using Hammer.JS. It's setup like this: "@angular/core": "~9.0.0-next.6", "hammerjs": "^2.0.8", "zone.js": "~0.10.2" app.module.ts is looking like this: import { BrowserModule, HammerGestureConfig,…
lampshade
  • 2,470
  • 3
  • 36
  • 74
12
votes
1 answer

Sync directional controls with swipe events

I've built two kinds of functionality in controlling the slider that I've built. One is buttons with directional controls and other is touch/swipe events. How can sync both of them so that when i press prev/next the swipe events is also updated and…
clestcruz
  • 1,081
  • 3
  • 31
  • 75
12
votes
6 answers

Using mobile events in Angular2

I was wondering if I could get some help in regards to events for mobile devices. I was looking around for a way to bind functions to swipe events in Angular 2. I saw in this this issue on Github that mentions that Angular 2 uses Hammer.js for…
Eric Gonzalo
  • 301
  • 1
  • 4
  • 10
12
votes
3 answers

Hammer.js event priority

I have implemented the hammer.js library for my events. The problem is that multiple events are triggered at the same time. Can I set somekind of event priority. Let's say when transforming is beeing done all other events are ignored. When…
Jacob
  • 3,580
  • 22
  • 82
  • 146
12
votes
4 answers

How to use hammer.js with Angular.js

I'm new with Angular.js and reading i know angular dont have events like tap, double tap, etc. I'm trying to combine with Hammer.js without success. Code from gist /** * angular-hammer.js * Inspired by AngularJS' implementation of "click dblclick…
rkmax
  • 17,633
  • 23
  • 91
  • 176
11
votes
2 answers

Google Chrome Pinch-to-zoom prevention

I'm developing an app for Chrome on a Microsoft Surface Pro 2 running Windows 8.1. Recently, the Chromium team decided they wanted to add the pinch-to-zoom gesture in Chrome for Windows 8, which is all and good. They did not, however, add a flag to…
Piper
  • 125
  • 1
  • 6
1
2 3
49 50