New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

pinchable

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pinchable

Lightweight, dependency-free library for smooth mobile pinch-zoom and panning on any HTML element.

latest
Source
npmnpm
Version
0.3.2
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Pinchable

Pinchable is a lightweight, dependency-free JavaScript library that adds smooth pinch-zoom and panning to any HTML element — perfect for mobile galleries.

npm Bundle size License: MIT

Demos

Try Pinchable live:

Try it on your phone

Scan to open the live demo:

PlaygroundReact demoVue demo
QR CodeQR CodeQR Code

Features

  • Smooth pinch-zoom anchored to touch center
  • Pan with edge clamping and threshold smoothing
  • Programmatic zooming via focus({ zoom, to }) using normalized [0–1] coordinates
  • Toggle gestures dynamically with setEnabled()
  • Event system: "start", "pinch", "end" + unsubscribe() helpers
  • Clean teardown with dispose()
  • Works with any DOM element — no frameworks, no dependencies

Installation

npm install pinchable

or

yarn add pinchable

Basic Usage

import { Pinchable } from "pinchable";

const container = document.getElementById("photo")!;

const pinchable = new Pinchable(container, {
    maxZoom: 3,
    minZoom: 0.5,
    edgeZoomThreshold: 0.2,
    nearZeroZoomThreshold: 0.07,
    shiftThreshold: 10,
    velocity: 0.7,
    applyTime: 400,
});

// Zoom to center
pinchable.focus({ zoom: 2, to: { x: 0.5, y: 0.5 } });

// Disable or enable gestures
pinchable.setEnabled(false);
pinchable.setEnabled(true);

// Subscribe to events
const unsubscribePinch = pinchable.subscribe("pinch", (zoom, shift) => {
    console.log("zoom", zoom, "shift", shift);
});

// Cleanup
unsubscribePinch();
pinchable.dispose();

API Reference

MethodDescription
focus({ zoom, to })Programmatically zoom to a specific normalized point
setEnabled(enabled: boolean)Enable or disable gestures
subscribe(event, handler)Listen to "start", "pinch", or "end" events (returns unsubscribe())
dispose()Remove listeners and reset element

Options

OptionDefaultDescription
maxZoom3Maximum zoom factor
minZoom1Minimum zoom factor
edgeZoomThreshold0.2Overshoot tolerance before clamping
nearZeroZoomThreshold0.07Smoothing zone near zoom = 1
shiftThreshold10Extra pixels beyond edges before clamping
velocity0.7Pinch sensitivity
applyTime400Duration (ms) for programmatic zoom transition

Compatibility

  • Touch devices only
  • Based on the Pointer Events API
  • Tested on iOS Safari and Android Chrome

Integrations

Development

git clone https://github.com/AlexanderShushunov/pinchable
cd pinch
npm install
npm run dev

License

MIT © Alexander Shushunov

Keywords: pinch zoom, gesture, touch, pan, mobile, pinchable, pinch-zoom, pointer events, no dependencies, vanilla js

Keywords

pinch

FAQs

Package last updated on 10 Oct 2025

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