Socket
Socket
Sign inDemoInstall

hammerjs

Package Overview
Dependencies
0
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hammerjs

A javascript library for multi-touch gestures


Version published
Weekly downloads
1.1M
decreased by-14.34%
Maintainers
2
Install size
890 kB
Created
Weekly downloads
 

Package description

What is hammerjs?

Hammer.js is a popular JavaScript library for handling touch gestures. It provides a simple way to recognize gestures made by touch, mouse, and pointer events, enabling developers to easily implement interactive features such as swiping, pinching, rotating, and pressing on web pages.

What are hammerjs's main functionalities?

Swipe Gesture

This code sample demonstrates how to detect left and right swipe gestures on an element. It initializes Hammer.js on a target element and listens for 'swipeleft' and 'swiperight' events.

var myElement = document.getElementById('myElement');
var mc = new Hammer(myElement);
mc.on('swipeleft swiperight', function(ev) {
    console.log(ev.type + " gesture detected.");
});

Pinch Gesture

This example shows how to enable and detect pinch gestures. It sets up pinch gesture recognition on an element and logs the scale of the pinch gesture.

var myElement = document.getElementById('myElement');
var mc = new Hammer(myElement);
mc.get('pinch').set({ enable: true });
mc.on('pinch', function(ev) {
    console.log("Pinch gesture detected with scale: " + ev.scale);
});

Rotate Gesture

This code snippet enables rotation gesture detection on an element. When a rotate gesture is detected, it logs the rotation angle.

var myElement = document.getElementById('myElement');
var mc = new Hammer(myElement);
mc.get('rotate').set({ enable: true });
mc.on('rotate', function(ev) {
    console.log("Rotate gesture detected with angle: " + ev.rotation);
});

Other packages similar to hammerjs

Changelog

Source

2.0.8, 2016-04-22

Manager
  • Added check to ensure that the required parameters are present (#908, 085d3a8)
  • Fixed restoration of Hammer.defaults.cssProps on destory (#904theregttr5ki, 7d0e60f)
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)

Readme

Source

Hammer.js 2.0.6

Build Status

Support, Questions, and Collaboration

Slack Status

Documentation

Visit hammerjs.github.io for detailed documentation.

// get a reference to an element
var stage = document.getElementById('stage');

// create a manager for that element
var mc = new Hammer.Manager(stage);

// create a recognizer
var Rotate = new Hammer.Rotate();

// add the recognizer
mc.add(Rotate);

// subscribe to events
mc.on('rotate', function(e) {
    // do something cool
    var rotation = Math.round(e.rotation);    
    stage.style.transform = 'rotate('+rotation+'deg)';
});

An advanced demo is available here: http://codepen.io/runspired/full/ZQBGWd/

Contributing

Read the contributing guidelines.

For PRs.

  • Use Angular Style commit messages
  • Rebase your PR branch when necessary
  • If you add a feature or fix a bug, please add or fix any necessary tests.
  • If a new feature, open a docs PR to go with.

Building

You can get the pre-build versions from the Hammer.js website, or do this by yourself running npm install -g grunt-cli && npm install && grunt build

Keywords

FAQs

Last updated on 22 Apr 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc