Code Monkey home page Code Monkey logo

pinch-zoom-canvas's Introduction

Pinch Zoom Canvas

Strongly inspired by img-touch-canvas.

It's a simple library for pinch to zoom an image based on a canvas element for smooth rendering. The library use a Impetus for adding a momentus on move the image zoomed. Impetus is not required but recommended.

Features:

  • Momentum for move the image zoomed
  • Pintch to zoom and center between the touches
  • Double tap to zoom
  • Stopping the event when the element is inactive

This plugin is written in Vanilla JS.

Tested on:

  • iOS Safari (8.x, 9.x)
  • Android Google Chrome
  • Cordova App
  • Google Chrome

Demo

Open this link into mobile device

Install

bower

$ bower install --save pinch-zoom-canvas

npm

$ npm install --save pinch-zoom-canvas

browser

<script src="pinch-zoom-canvas.js"></script>

Options

  • canvas mandatory. It is a DOM element where the image is rendered.
  • path mandatory. It is a path url of image.
  • doubletap optional (default true). Double tap for zooming.
  • momentum optional (defalut false). Set a momentum when the image is dragged. This parameter require Impetus library.
  • maxZoom optional (default 2). It is the zoom max.
  • onZoomEnd optional (default null). It is a callback function called when the pinch ended.
  • onZoom optional (default null). It is a callback function called when zooming.
  • threshold optional (default 40). Area (in px) of the screen to release touch events.

API

pause()

Stop the render canvas.

resume()

Resume the render canvas.

calculateOffset()

Update the canvas offset.

isZommed()

Return a boolean value for the image state of zoomed.

destroy()

Stop all events and render canvas.

Usage

<canvas id="mycanvas" style="width: 100%; height: 100%"></canvas>
var pinchZoom = new PinchZoomCanvas({
	canvas: document.getElementById('mycanvas'),
	path: "your image url",
	momentum: true,
	zoomMax: 2,
	doubletap: true,
	onZoomEnd: function (zoom, zoomed) {
		console.log("---> is zoomed: %s", zoomed);
		console.log("---> zoom end at %s", zoom);
	},
	onZoom: function (zoom) {
		console.log("---> zoom is %s", zoom);
	}
	});

Licence


See the LICENSE file.

pinch-zoom-canvas's People

Contributors

vash15 avatar johnwest80 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.