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

@types/hammerjs

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/hammerjs

TypeScript definitions for hammerjs

  • 2.0.46
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • ts5.2
  • ts5.3
  • ts5.4
  • ts5.5
  • ts5.6
  • ts5.7
  • ts5.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.5M
increased by3.52%
Maintainers
1
Weekly downloads
 
Created

What is @types/hammerjs?

The @types/hammerjs package provides TypeScript type definitions for Hammer.js, a popular library for handling touch gestures. By using these type definitions, developers can get compile-time type checking and IntelliSense support in TypeScript projects when working with Hammer.js.

What are @types/hammerjs's main functionalities?

Gesture recognition

This code sets up gesture recognition on an HTML element to detect various gestures such as pan and tap, and updates the element's text content with the type of gesture detected.

import Hammer from 'hammerjs';

const myElement = document.getElementById('myElement');
const mc = new Hammer(myElement);

mc.get('pan').set({ direction: Hammer.DIRECTION_ALL });

mc.on('panleft panright panup pandown tap press', function(ev) {
    myElement.textContent = ev.type + "!";
});

Custom gesture configuration

This code configures the swipe gesture to only recognize vertical movements and applies a translation transformation to the HTML element based on the swipe's vertical delta.

import Hammer from 'hammerjs';

const myElement = document.getElementById('myElement');
const mc = new Hammer(myElement);

mc.get('swipe').set({ direction: Hammer.DIRECTION_VERTICAL });

mc.on('swipeup swipedown', function(ev) {
    myElement.style.transform = `translateY(${ev.deltaY}px)`;
});

Event data handling

This code demonstrates how to handle pinch events and access event data such as the scale of the pinch and the center point of the gesture.

import Hammer from 'hammerjs';

const myElement = document.getElementById('myElement');
const mc = new Hammer(myElement);

mc.on('pinch', function(ev) {
    // Access event data like scale and center
    console.log(`Pinch scale: ${ev.scale}, center: ${ev.center}`);
});

Other packages similar to @types/hammerjs

FAQs

Package last updated on 07 Oct 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