No description, website, or topics provided.
Branch: master
Clone or download
Latest commit 7b74146 Jan 16, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist Add minScale attribute/property (#6) Jan 16, 2019
lib Add minScale attribute/property (#6) Jan 16, 2019
.gitignore Ignore cache Nov 9, 2018
LICENSE Initial commit Oct 10, 2018
README.md Adding demo Nov 9, 2018
package-lock.json 1.1.0 Jan 16, 2019
package.json 1.1.0 Jan 16, 2019
rollup.config.js Initial commit Nov 9, 2018
tsconfig.json Initial commit Nov 9, 2018
tslint.json Initial commit Nov 9, 2018

README.md

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.