# pan-zoom

> Pan and zoom events for any element

Latest version **3.5.2** (published 2020-11-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install pan-zoom
pnpm add pan-zoom
yarn add pan-zoom
bun add pan-zoom
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.5.2 |
| Published | 2020-11-27 |
| First published | 2016-10-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 91 |
| Author | dmitry iv |
| Maintainers | dfcreative, dy |
| Keywords | pan, zoom, pinch, touch, canvas, webgl |

## Links

- npm: https://www.npmjs.com/package/pan-zoom
- Repository: https://github.com/dy/pan-zoom
- Homepage: https://github.com/dy/pan-zoom#readme
- Issues: https://github.com/dy/pan-zoom/issues
- npm.io page: https://npm.io/package/pan-zoom

## Dependencies (5)

- [impetus](https://npm.io/package/impetus.md) ^0.8.8
- [mouse-wheel](https://npm.io/package/mouse-wheel.md) ^1.2.0
- [touch-pinch](https://npm.io/package/touch-pinch.md) ^1.0.1
- [touch-position](https://npm.io/package/touch-position.md) ^2.0.0
- [has-passive-events](https://npm.io/package/has-passive-events.md) ^1.0.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 3.5.2 (latest) — 2020-11-27
- 3.5.1 — 2020-09-18
- 3.5.0 — 2019-08-07
- 3.4.1 — 2019-06-11
- 3.4.0 — 2018-10-30
- 3.3.0 — 2018-09-06
- 3.2.2 — 2018-08-14
- 3.2.1 — 2018-07-29
- 3.2.0 — 2018-07-29
- 3.1.0 — 2018-06-12
- 3.0.0 — 2018-06-12
- 2.3.2 — 2018-04-05
- 2.3.1 — 2018-04-05
- 2.3.0 — 2018-03-15
- 2.2.1 — 2018-03-15
- … 9 more at https://npm.io/package/pan-zoom/versions

## README

# pan-zoom ![tiny](https://img.shields.io/badge/gzipped-4.8kb-brightgreen.svg) [![unstable](http://badges.github.io/stability-badges/dist/unstable.svg)](http://github.com/badges/stability-badges)

Panning and zooming events for any target. May come handy for webgl, canvas, svg, images or pure html manipulations. Handles mobile pinch-zoom, drag and scroll interactions, provides inertial movement.

See [demo](https://dy.github.io/plot-grid).

[![npm install pan-zoom](https://nodei.co/npm/pan-zoom.png?mini=true)](https://npmjs.org/package/pan-zoom/)

```js
const panzoom = require('pan-zoom');

let unpanzoom = panzoom(document.body, e => {
  // e contains all the params related to the interaction

  // pan deltas
  e.dx;
  e.dy;

  // zoom delta
  e.dz;

  // coordinates of the center
  e.x;
  e.y;

  // type of interaction: mouse, touch, keyboard
  e.type;

  // target element event is applied to
  e.target;

  // original element event started from
  e.srcElement;

  // initial coordinates of interaction
  e.x0;
  e.y0;
});

// call to remove panzoom handler from the target
unpanzoom()
```

See [`test.js`](https://github.com/dy/pan-zoom/blob/master/test.js) for basic use-case.

## Alternatives

* [@soulfresh/pan-zoom](https://github.com/soulfresh/pan-zoom#readme) − compatible fork with elaborate API and fixes.

## Credits

This package puts together high-quality tiny components, so acknowledgment to their authors:

* [impetus](http://npmjs.org/package/impetus) by **[Chris Bateman @chrisbateman](https://github.com/chrisbateman)** handles inertial drag.
* [mouse-wheel](https://github.com/mikolalysenko/mouse-wheel) by **[Mikola Lysenko @mikolalysenko](https://github.com/mikolalysenko/mouse-wheel)** covers cross-browser wheel event.</del>
* [touch-pinch](https://www.npmjs.com/package/touch-pinch) by **[Matt DesLauriers @mattdesl](https://github.com/mattdesl)** handles mobile pinch gestures.
* [touch-position](https://www.npmjs.com/package/touch-position) by **[Matt DesLauriers @mattdesl](https://github.com/mattdesl)** tracks mouse and touch coordinates.

## License

© 2017 Dmitry Yv. MIT License

---
_Source: https://npm.io/package/pan-zoom · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
