Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@types/hammerjs
Advanced tools
TypeScript definitions for 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.
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}`);
});
ZingTouch is a modern JavaScript touch gesture library that provides custom, complex touch gestures. It is similar to Hammer.js in that it allows for the creation of touch-based events but offers a different API and additional custom gestures.
AlloyFinger is a tiny gesture library that offers a simple API for handling touch events. It is lighter than Hammer.js and provides similar functionalities but with a focus on performance and a smaller footprint.
Interact.js is a JavaScript library for draggable, resizable, and multi-touch gestures. It is more comprehensive than Hammer.js, offering additional features like drag and drop and resizing, but it may be more complex to use for simple gesture recognition tasks.
npm install --save @types/hammerjs
This package contains type definitions for hammerjs (http://hammerjs.github.io/).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/hammerjs.
These definitions were written by Han Lin Yap.
FAQs
TypeScript definitions for hammerjs
The npm package @types/hammerjs receives a total of 1,239,099 weekly downloads. As such, @types/hammerjs popularity was classified as popular.
We found that @types/hammerjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.