Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

propagating-hammerjs

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

propagating-hammerjs

Extend hammer.js with event propagation

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
264K
decreased by-10.8%
Maintainers
1
Weekly downloads
 
Created

What is propagating-hammerjs?

The `propagating-hammerjs` package is a wrapper around the popular `hammer.js` library, which is used for handling touch gestures in web applications. This wrapper adds event propagation capabilities to `hammer.js`, allowing touch events to bubble up through the DOM, similar to how native DOM events work.

What are propagating-hammerjs's main functionalities?

Basic Gesture Handling

This feature allows you to handle basic touch gestures like pan, pinch, rotate, etc., on a specific DOM element. The events will propagate up the DOM tree, allowing for more flexible event handling.

const Hammer = require('hammerjs');
const PropagatingHammer = require('propagating-hammerjs');

const element = document.getElementById('myElement');
const hammer = PropagatingHammer(new Hammer(element));

hammer.on('pan', function(event) {
  console.log('Pan gesture detected:', event);
});

Event Propagation

This feature demonstrates how touch events can propagate from child elements to parent elements. In this example, both the parent and child elements can handle the 'tap' gesture, and the event will bubble up from the child to the parent.

const Hammer = require('hammerjs');
const PropagatingHammer = require('propagating-hammerjs');

const parentElement = document.getElementById('parentElement');
const childElement = document.getElementById('childElement');

const parentHammer = PropagatingHammer(new Hammer(parentElement));
const childHammer = PropagatingHammer(new Hammer(childElement));

parentHammer.on('tap', function(event) {
  console.log('Tap gesture detected on parent:', event);
});

childHammer.on('tap', function(event) {
  console.log('Tap gesture detected on child:', event);
});

Custom Gesture Recognition

This feature allows you to define custom gestures. In this example, a custom 'doubletap' gesture is created and added to the Hammer instance. The event will propagate through the DOM as expected.

const Hammer = require('hammerjs');
const PropagatingHammer = require('propagating-hammerjs');

const element = document.getElementById('myElement');
const hammer = PropagatingHammer(new Hammer(element));

const customRecognizer = new Hammer.Tap({ event: 'doubletap', taps: 2 });
hammer.add(customRecognizer);

hammer.on('doubletap', function(event) {
  console.log('Double tap gesture detected:', event);
});

Other packages similar to propagating-hammerjs

Keywords

FAQs

Package last updated on 25 Jan 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc