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

Related tags

Gesture hammer.js
Overview

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

Comments
  • Looking for a maintainer.

    Looking for a maintainer.

    I'm looking for someone who would like to maintain Hammer.js. Unfortunately I just don't have enough time left for the project due a new job, and don't have use the library myself these days.

    Requirements of a new maintainer should be that he is aware of the impact of the changes, since the project is being used in quite a lot of websites/apps. It has almost 10K stars, so it comes with some responsibility.

    Some of the key features of Hammer;

    • Speed; Hammer is being called on every mouse/touch-move, so keep the code as simple as possible
    • Clean of overhead/sugar; To keep the library small and focused, I dont'want all kinds of small additions to support X feature for some edge cases. Hammer is/should be quite modular so some hooks are fairly easy to implement.
    • Small minified filesize.
    • No dependencies.

    If you are interested, and can find yourself in the points above, please contact me!

    https://twitter.com/jorikdelaporik

    question 
    opened by jtangelder 47
  • Swipe event doesn't work in Chrome 55.0

    Swipe event doesn't work in Chrome 55.0

    We use leftSwipe and rightSwipe to detect the event but neither of it works in Chrome with version higher than 55.0. But before it worked in Chrome 54.0 and version lower than 55.0. Also tried in Firefox and Safari, and both of them work fine.

    hammer.add(new Hammer.Swipe({ event: "leftSwipe", direction: Hammer.DIRECTION_LEFT }));
    hammer.add(new Hammer.Swipe({ event: "rightSwipe", direction: Hammer.DIRECTION_RIGHT }));
    

    This problem can also be test here https://hammerjs.github.io/

    opened by AliceClarity 30
  • Looking for team members

    Looking for team members

    To help improve the future viability of this project we are going to build a team around the project.

    Any one interested in helping please comment here with in what ways you think you would be willing / able to help. I started an IRC channel for development and support #hammer.js on freenode! would love to see any one interested there!

    question 
    opened by arschmitz 29
  • Scrolling disabled on Hammer.js element

    Scrolling disabled on Hammer.js element

    In my angular 2 app I have a carousel element which has the swipe-right and swipe-left functionality implemented.

    The issue is that if I'm mobile (or emulate mobile in Chrome) and I try to scroll above or below that element by first clicking on my element and dragging I cannot scroll my page. In mobile it's 100% of the width so it's going to be a common user scenario. If I remove the swipe-right and swipe-left functionality it works as expected.

    I read somewhere that this requires changing the css to include touch-action: pan-y !important. This works in the desktop chrome emulator but not for chrome on an actual mobile device (iPhone 6).

    Is there any better work around?

    Is there any additional css I need to make scrolling function as normal on all browsers?

    opened by eplatzek 26
  • Cannot be used with virtual DOMs

    Cannot be used with virtual DOMs

    It seems as Hammer can’t leave elements in peace. For touch events, this inline style is set on elements:

    touch-action: pan-y; -webkit-user-select: none; -webkit-user-drag: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    

    This completely eliminates any hope for using this library with virtual DOMs. Sadly! :(

    question wontfix Support 
    opened by Frikki 23
  • hammer.js 1.1.2 breaks on Windows Phone 8

    hammer.js 1.1.2 breaks on Windows Phone 8

    Hi there.

    I've noticed that from version 1.1.1 to 1.1.2 hammer.js stopped working on Windows Phone 8.

    I've tried to apply the changes defined in #430 but had no success.

    It still runs ok on W8/8.1 desktop, but I had to revert to version 1.1.1 to get my project running across Android/iOS/Windows.

    Hope this helps!

    opened by rodrigobahiense 22
  • adding hammer to the body tag in ie10 disables scrolling via touch

    adding hammer to the body tag in ie10 disables scrolling via touch

    ...specifcially with the -ms-touch-action: none style being set. when I set stop_browser_behavior to false this fixes that issue, but then drag hammer events don't properly work since the page wants to scroll.

    I'm not really sure what the best solution here is; ideally one could conditionally disable and re-enable default browser behavior when convenient. Our use case is that we want a hold event to trigger an element to become draggable. The browser behavior would be stopped once the hold gesture triggers, and it would then be restarted when the drag event is finished.

    opened by klundberg 22
  • Support for mousewheel?

    Support for mousewheel?

    Is there support for mousewheel in hammer.js v2?

    Or can it be easily done with a custom recognizer? I'm unsure how to go about this; the docs seems lacking on this.

    opened by dashed 21
  • swipeleft, swiperight, swipeup, swipebottom don't work on Chrome 29 for Android

    swipeleft, swiperight, swipeup, swipebottom don't work on Chrome 29 for Android

    I've been working on a simple swipe menu for a webapp of mine using Hammer.js while I noticed that the swipe events I've mentioned in the title don't get fired (can't debug because I have some adb issues with the drivers and windows 8.1). It only happens in Chrome for Android while the default Browser for android 4.1 works fine.

    Hammer.JS - v1.0.5, Chrome 29 for Android

    tested this in 2 Android devices: Archos Platinum 50 (phone), HP Touchpad (tablet).

    opened by varemenos 20
  • Hammer.js makes -webkit-overflow-scrolling: touch buggy on iOS

    Hammer.js makes -webkit-overflow-scrolling: touch buggy on iOS

    When using Hammer.js on element inside of a container with -webkit-overflow-scrolling: touch on it, scrolling got jumpy and less smooth.

    I observed this simply when calling Hammer(element), without any of my own code.

    For now I've solved it by just stripping out Hammer.js and creating my own touch handling, but I'm still submitting this issue (although I didn't see it mentioned before).

    Note: It's also worthwhile I think, for Hammer.js to check and make sure the parent container's scrollTop hasn't changed between touchstart and touchmove/touchend, to be sure of whether or not it's a scroll event (iOS doesn't provide a live scroll event for native scrolling) - this was a huge help in my code.

    opened by matt-curtis 20
  • stopPropagation() not working with tap event

    stopPropagation() not working with tap event

    I can't seem to get stopPropagation to work. I want to make the child div trigger the alert without causing the link to be called. I tried putting stopPropagation() and preventDefault() on all the events - I tried this in chrome and IOS.

      <a href='http://www.google.com' target="_blank">boo
        <div id='test_el' style='background:red;color:blue'>Hello world</div>
      </a>
    
     var element = document.getElementById('test_el');
        var hammertime = Hammer(element,{
            prevent_default:true
        }).on("tap", function(event) {
            event.stopPropagation();
            event.preventDefault();
            event.gesture.stopPropagation();
            event.gesture.preventDefault();
            event.gesture.srcEvent.stopPropagation();
            event.gesture.srcEvent.preventDefault();
            event.gesture.startEvent.stopPropagation();
            event.gesture.startEvent.preventDefault();
            alert('hello!');
        });
    

    Here is plunker

    http://plnkr.co/edit/Pr5pqy?p=preview

    opened by wlow84 18
  • Use https instead of git protocol for repository

    Use https instead of git protocol for repository

    As Github has disabled the Git protocol[0], accessing this repo using git:// is no longer possible and results in a time-out. This causes problems when Yarn attempts to download this package[1]. Changing this to https should solve this.

    [0] https://github.blog/2021-09-01-improving-git-protocol-security-github/ [1] https://github.com/yarnpkg/yarn/issues/8833

    opened by dopeh 0
  • swipe and tap action in android

    swipe and tap action in android

    Hi. I am using hammerjs for mobile devices. In service, we are using double tap as "Like" action and swipe as "Next or Previous content" action.

    In android devices, a little dragged tap seems to be handled as swipe. So double tap hardley works (as "Like" action) because "a little dragged tap" is handled as swipe. Almost every double tap action goes like "swipe - tap" or "tap - swipe" (even "swipe - swipe") I tried two ways to solve this.

    1. use recognizeWith to bind tap and swipe
    2. change options of swipe action

    As I figured out solution 1 is not available, I tried solution 2. However, changing swipe action's velocity and threshold doesn't work.

    Can I get any other solution for divide swipe and tap more specifically?

    opened by seeungKang 0
  • Swipe prevents onclick outside element from triggering

    Swipe prevents onclick outside element from triggering

    Hi

    I have modified tests/manual/input.html to illustrate the issue. Below, I have added a button which alerts "On click" in the onclick event. If we swipe in the hit area and quickly click/tap the button, the onclick is not triggered. Tap events are OK, looks like it is only the swipe action which is causing this behavior.

    <div id="hit" class="bg1" style="padding: 30px; height: 200px;">
    </div>
    <button onclick="alert('On click'); return false;" style="width: 300px;height:200px;">Click Me</button>
    

    Any pointers as to where in the source I can track this down? Ideally, I would like the onclick of the button to trigger regardless of the touch actions that is happening in the hit area.

    opened by keithchew 0
  • swipe event does not allow playing audio on iOS

    swipe event does not allow playing audio on iOS

    On mobile devices, playing media with mediaElement.play() needs explicit user interaction. On Android, playing media on swipe event works. On the other side on iOS, it does not work with following error.

    Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

    opened by orange4glace 0
  • How to get single finger Pan and 2 finger pan at the same time?

    How to get single finger Pan and 2 finger pan at the same time?

    Hi, We are trying to capture events when user drag on screen with 2 finger and at the same time a third finger pan happens How can we capture the third finger pan as a seperate event when 2 finger pan is already in progress.

    codepen demo https://codepen.io/AdnaanS/pen/jOyoNbY demo where i tried 2 hammer instance https://codepen.io/AdnaanS/pen/QWdRLdQ We have already tried recognizeWith and requireFailure combinations but nothing seems to work

    Any help is appreciated

    opened by Adnaan03 0
Super tiny size multi-touch gestures library for the web.    You can touch this →

Preview You can touch this → http://alloyteam.github.io/AlloyFinger/ Install You can install it via npm: npm install alloyfinger Usage var af = new Al

腾讯 AlloyTeam 3.3k Dec 12, 2022
👇 Bread n butter utility for component-tied mouse/touch gestures in Svelte.

svelte-gesture svelte-gesture is a library that lets you bind richer mouse and touch events to any component or view. With the data you receive, it be

Robert Soriano 29 Dec 21, 2022
👇 Bread n butter utility for component-tied mouse/touch gestures in Solid.

solid-gesture solid-gesture is a port of @use-gesture/react which lets you bind richer mouse and touch events to any component or view. With the data

Robert Soriano 8 Sep 30, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
App that allows you to control and watch YouTube videos using hand gestures. Additionally, app that allows you to search for videos, playlists, and channels.

YouTube Alternative Interaction App An app I made with Edward Wu that allows you to search and watch videos from YouTube. Leverages Google's YouTube D

Aaron Lam 2 Dec 28, 2021
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Pressure is a JavaScript library for handling both Force Touch and 3D Touch on the web

Pressure is a JavaScript library for handling both Force Touch and 3D Touch on the web, bundled under one library with a simple API that makes working with them painless.

Stuart Yamartino 2.9k Dec 29, 2022
noUiSlider is a lightweight JavaScript range slider library with full multi-touch support. It fits wonderfully in responsive designs and has no dependencies.

noUiSlider noUiSlider is a lightweight JavaScript range slider. No dependencies All modern browsers and IE > 9 are supported Fully responsive Multi-to

Léon Gersen 5.4k Dec 28, 2022
Conveyer adds Drag gestures to your Native Scroll.

Conveyer Demo / Documentation / Other components Conveyer adds Drag gestures to your Native Scroll. ?? ?? ?? ✨ Features You can use Native Scroll-like

NAVER 70 Dec 15, 2022
A refined tool for exploring open-source projects on GitHub with a file tree, rich Markdown and image previews, multi-pane multi-tab layouts and first-class support for Ink syntax highlighting.

Ink codebase browser, "Kin" ?? The Ink codebase browser is a tool to explore open-source code on GitHub, especially my side projects written in the In

Linus Lee 20 Oct 30, 2022
proxy 🦄 yxorp is your Web Proxy as a Service (SAAS) Multi-tenant, Multi-Threaded, with Cache & Article Spinner

proxy ?? yxorp is your Web Proxy as a Service (SAAS) Multi-tenant, Multi-Threaded, with Cache & Article Spinner. Batteries are included, Content Spinning and Caching Engine, all housed within a stunning web GUI. A unique high-performance, plug-and-play, multi-threaded website mirror and article spinner

4D/ҵ.com Dashboards 13 Dec 30, 2022
Bot WhatsApp multi device / multi perangkat menggunakan lib / api baileys-md. Give star ⭐

Requirements • Installation • Thanks to • Official Group Bot • Donate Information Chika-Md adalah bot yang awalnya memakai base dari Hisoka-Morou. Chi

Riy 57 Dec 25, 2022
whatsapp api to remote your whatsapp device. Support multi device, multi client. Still update to more feature. Please fork, star, donate and share.

Ndalu-wa-client DEPENDENCIES : { "@adiwajshing/baileys": "^4.2.0", "@adiwajshing/keyed-db": "^0.2.4", "axios": "^0.27.2", "body-parser

null 29 Jan 4, 2023
This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do any operations that can be performed in python shell with this package.

Django execute code This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do

Shinu 5 Nov 12, 2022
This package will help parse OData strings (only the Microsoft Dataverse subset). It can be used as a validator, or you can build some javascript library which consumes the output of this library.

@albanian-xrm/dataverse-odata This package will help parse OData strings (only the Microsoft Dataverse subset). It can be used as a validator, or you

AlbanianXrm 3 Oct 22, 2022