explaingit

hammerjs/hammer.js

24,352JavaScriptAudience · developerComplexity · 2/5MaintainedLicenseSetup · easy

TLDR

JavaScript library that detects touch gestures like swipes, taps, and pinches so you can respond to them without writing complex low-level code.

Mindmap

mindmap
  root((Hammer.js))
    What it does
      Detects touch gestures
      Simplifies event handling
      Works with any element
    Gesture types
      Tap and double tap
      Swipe in directions
      Pinch and rotate
      Press and hold
    Use cases
      Mobile carousels
      Drag and drop
      Pinch to zoom
      Touch-driven apps
    Tech stack
      Pure JavaScript
      No dependencies
      Browser APIs
    Customization
      Custom recognizers
      Define own gestures
      Configure thresholds

Things people build with this

USE CASE 1

Build touch-driven carousels and sliders that respond to swipe gestures on mobile devices.

USE CASE 2

Create pinch-to-zoom image viewers and map interfaces that scale content with two-finger gestures.

USE CASE 3

Implement drag-and-drop interfaces that feel native on tablets and phones.

USE CASE 4

Add custom gesture recognition like triple-tap or multi-finger swipes to web apps.

Tech stack

JavaScriptDOM APITouch Events

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

Hammer.js is a JavaScript library that makes it easy to detect touch and gesture interactions on web pages. Normally, tracking gestures like swipes, taps, pinches, or presses involves writing complicated low-level code to interpret raw touch events from the browser. Hammer.js handles all that complexity so you can simply say "when the user swipes left, do this" without worrying about the underlying mechanics. It works by attaching a listener to any HTML element on your page. You then subscribe to named gesture events, tap, double tap, press, swipe, and so on, and provide a function to run when that gesture is detected. For custom gestures not included by default, you can define your own recognizers with specific rules (for example, a triple tap). You would use this when building a web app that needs to feel native on mobile devices: touch-driven carousels, drag-and-drop interfaces, pinch-to-zoom image viewers, or any interactive experience where mouse clicks aren't enough. It is a pure JavaScript library with no framework dependency, so it works with any web project.

Copy-paste prompts

Prompt 1
Show me how to use Hammer.js to detect a swipe-left gesture and trigger a carousel slide transition.
Prompt 2
How do I set up Hammer.js to recognize a pinch gesture and zoom an image element in and out?
Prompt 3
Create a custom Hammer.js recognizer that detects a triple-tap gesture and logs it to the console.
Prompt 4
I want to add Hammer.js to my existing web app to make a drag-and-drop interface work on touch devices. What's the minimal setup?
Prompt 5
How do I configure Hammer.js to detect both tap and long-press gestures on the same element?
Open on GitHub → Explain another repo

Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.