Find a file
Tusooa Zhu a94fb753a1
Support disabling panning at min scale and selectively passing down pointer events
At min scale we can now disable panning (but still get pinch actions).
In that case the pan will be passed down.
Once the pan is turned into a pinch, it will no longer be passed down,
and a pointercancel will be triggered on the parent.
2021-08-02 16:48:32 -04:00
dist Support disabling panning at min scale and selectively passing down pointer events 2021-08-02 16:48:32 -04:00
lib Support disabling panning at min scale and selectively passing down pointer events 2021-08-02 16:48:32 -04:00
.gitignore Ignore cache 2018-11-09 14:12:25 -08:00
LICENSE Initial commit 2018-10-10 11:15:41 -07:00
package-lock.json Rebrand package 2021-08-02 13:04:11 -04:00
package.json Support disabling panning at min scale and selectively passing down pointer events 2021-08-02 16:48:32 -04:00
README.md Adding demo 2018-11-09 14:11:09 -08:00
rollup.config.js fix: fix "pointer-tracker not found" webpack error (#12) 2019-02-22 09:33:09 +00:00
tsconfig.json Initial commit 2018-11-09 12:40:51 -08:00
tslint.json Initial commit 2018-11-09 12:40:51 -08:00

A web component for pinch zooming DOM elements.

Usage

npm install --save-dev pinch-zoom-element
<pinch-zoom>
  <h1>Hello!</h1>
</pinch-zoom>

Now the above can be pinch-zoomed!

API

<pinch-zoom class="my-pinch-zoom">
  <h1>Hello!</h1>
</pinch-zoom>
<script>
  const pinchZoom = document.querySelector('.my-pinch-zoom');
</script>

Properties

pinchZoom.x; // x offset
pinchZoom.y; // y offset
pinchZoom.scale; // scale

Methods

Set the transform. All values are optional.

pinchZoom.setTransform({
  scale: 1,
  x: 0,
  y: 0,
  // Fire a 'change' event if values are different to current values
  allowChangeEvent: false,
});

Scale in/out of a particular point.

pinchZoom.scaleTo(scale, {
  // Transform origin. Can be a number, or string percent, eg "50%"
  originX: 0,
  originY: 0,
  // Should the transform origin be relative to the container, or content?
  relativeTo: 'content',
  // Fire a 'change' event if values are different to current values
  allowChangeEvent: false,
});

Demo

Simple image pinch-zoom. Although you can put any element in <pinch-zoom>.

Files

  • lib/index.ts - Original TypeScript.
  • dist/pinch-zoom.mjs - JS module. Default exports PinchZoom.
  • dist/pinch-zoom.js - Plain JS. Exposes PinchZoom on the global.
  • dist/pinch-zoom-min.js - Minified plain JS. 2.3k gzipped.