• Stars
    star
    915
  • Rank 49,917 (Top 1.0 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 12 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Javascript library providing multi-touch gestures for zooming and dragging on any DOM element.

PinchZoom.js

PinchZoom is a Javascript library providing multi-touch gestures for zooming and dragging on any DOM element.

Installation

Usage

Requirements

Initialisation

let el = document.querySelector('#my-id');
let pz = new PinchZoom(el, options);

Options


tapZoomFactor:      Zoom factor that a double tap zooms to. (default 2)
zoomOutFactor:      Resizes to original size when zoom factor is below this value. (default 1.3)
animationDuration:  Animation duration in milliseconds. (default 300)
maxZoom:            Maximum zoom factor. (default 4)
minZoom:            Minimum zoom factor. (default 0.5)
draggableUnzoomed:  Capture drag events even when the image isn't zoomed. (default true)
                    (using `false` allows other libs (e.g. swipe) to pick up drag events)
lockDragAxis:       Lock panning of the element to a single axis. (default false)
setOffsetsOnce:     Compute offsets (image position inside container) only once. (default false)
                    (using `true` maintains the offset on consecutive `load` and `resize`)
use2d:              Fall back to 2D transforms when idle. (default true)
                    (a truthy value will still use 3D transforms during animation)
useMouseWheel:      Use mouse wheel zoom and mouse drag. (default false)
verticalPadding:    Vertical padding to apply around the image. (default 0)
horizontalPadding:  Horizontal padding to apply around the image. (default 0)

onZoomStart:        Callback for zoomstart event (params: Pinchzoom object, Event event) (default null)
onZoomEnd:          Callback for zoomend event (params: Pinchzoom object, Event event) (default null)
onZoomUpdate:       Callback for zoomupdate event (params: Pinchzoom object, Event event) (default null)
onDragStart:        Callback for dragstart event (params: Pinchzoom object, Event event) (default null)
onDragEnd:          Callback for dragend event (params: Pinchzoom object, Event event) (default null)
onDragUpdate:       Callback for dragupdate event (params: Pinchzoom object, Event event) (default null)
onDoubleTap:        Callback for doubletap event (params: Pinchzoom object, Event event) (default null)

Methods

let pz = new PinchZoom(myElement);

pz.enable(); // Enables all gesture capturing (is enabled by default)
pz.disable(); // Disables all gesture capturing
pz.destroy(); // Unmounts the zooming container and global event listeners

Example with callback

var myElement = document.getElementById("myElement");
var pz = new PinchZoom.default(myElement, {
    draggableUnzoomed: false,
    minZoom: 1,
    onZoomStart: function(object, event){
        // Do something on zoom start
        // You can use any Pinchzoom method by calling object.method()
    },
    onZoomEnd: function(object, event){
        // Do something on zoom end
    }
})

Events (deprecated)

Events are deprecated in favour of callbacks (see above).

Pinchzoom emits custom events you can listen to:


pz_zoomstart  Started to zoom
pz_zoomend    Stopped zooming
pz_zoomupdate Zoom factor updated
pz_dragstart  Started to drag the element
pz_dragend    Stopped to drag the element
pz_dragupdate Drag position updated
pz_doubletap  Resetting the zoom with double-tap

(if need be, the event names can be customized via options)

Release a New Version

  1. Make a bump commit (update package.json, package-lock.json and src)
  2. Create a new tag git tag -m "v2.2.0" v2.2.0
  3. Release new NPM version (npm whoami; npm publish)
  4. Push the code + the tag to Github (git push origin v2.2.0)
  5. Make a new Github release (https://github.com/manuelstofer/pinchzoom/releases)

Troubleshooting

  • If you have issues with invisible images, make sure that the image isn't absolutely positioned. In some cases that will cause trouble.

License

Licensed under the MIT License.

Github Page with demo

https://manuelstofer.github.io/pinchzoom/

More Repositories

1

json-pointer

Some utilities for the JSON pointers described by RFC 6901
JavaScript
177
star
2

foreach

Foreach component + npm package
JavaScript
25
star
3

qry

Creates match functions from MongoDB query objects.
JavaScript
10
star
4

led-ticker

Network daemon for my AM03128-H11 led ticker
Python
7
star
5

websocket-multiplexer

Multiple virtual channels over a web socket / SockJS connection
JavaScript
6
star
6

component-travis-mocha-phantomjs-chai

test setup for components with travis support
JavaScript
4
star
7

pflock

Two way data bindings
JavaScript
3
star
8

each

Underscore's each function packed as a component
JavaScript
3
star
9

esformatter-limit-linebreaks

esformatter linebreak limit plugin
JavaScript
3
star
10

is

type checking component
JavaScript
3
star
11

bibimbap

JavaScript
2
star
12

backbone-pflock

Two way data bindings for Backbone models using Pflock
JavaScript
2
star
13

content-element

Experimental real-time content editing
JavaScript
2
star
14

ahead

An experiment with promises
JavaScript
2
star
15

websocket-rpc-stream

RPC over websockets with progress updates.
JavaScript
2
star
16

toolbar

Flyout toolbar
JavaScript
2
star
17

repo

Experimental real-time storage API for MongoDB over socket.io
JavaScript
1
star
18

md5

Yoshinori Kohyama's md5 implementation packed as component
JavaScript
1
star
19

drums

Drum machine component built with the web audio api
JavaScript
1
star
20

load-samples

Loads audio samples for use with Web-Audio-API
JavaScript
1
star
21

insert

Insert HTML/Elements to the DOM
JavaScript
1
star
22

extend

Underscore's extend function packed as a component
JavaScript
1
star
23

mapr

Map for objects
JavaScript
1
star
24

listener

addEventListener with ie fallback
JavaScript
1
star
25

papply

Left and right partial application without context
JavaScript
1
star
26

ce-images

Image upload plugin for content-element
JavaScript
1
star
27

elm-gameoflife

Elm
1
star
28

range

Underscore's range function packed as a component
JavaScript
1
star
29

slow-click

Edit linked content editables with slow clicks
JavaScript
1
star
30

claim

Util to check if dom elements belong to a view or sub view
JavaScript
1
star
31

es6map

Paul Millr's es6-shim Map implementation packed as a component
JavaScript
1
star
32

templates

Dummy component for generated templates
JavaScript
1
star
33

sockjs-websockify

SockJS connection wrapper. Makes connections more web socket like.
JavaScript
1
star
34

koboldmaki

Views inspired by backbone, built with components only.
JavaScript
1
star