Coder Social home page Coder Social logo

sanichkotikov / pinch-zoom-pan Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 4.0 93 KB

A simple module that add pinch-zoom and pan to your HTML element

Home Page: https://sanichkotikov.github.io/react-family-tree-example/

License: MIT License

TypeScript 100.00%
pinch zoom pan npm-package npm-module nativejs

pinch-zoom-pan's Introduction

pinch-zoom-pan

A simple module that add pinch-zoom and pan to your HTML element.

Using

npm i -S pinch-zoom-pan
<div class="root" id="root">
  <div class="point">
    <div class="canvas">
      <!-- your content here -->
    </div>
  </div>
</div>
.root {
  position: relative;
  transform: translateZ(0);
  overflow: hidden;
}

.point {
  position: absolute;
  width: 0;
  height: 0;
  transform: translate(0, 0) scale(1);
  transform-origin: center;
  will-change: transform;
}

.canvas {
  position: absolute;
  transform: translate(-50%, -50%);
}
import { create } from 'pinch-zoom-pan';

// Run module on mount
const canvas = create({
  element: document.getElementById('root'),
  // optional settings:
  minZoom: 0.5,
  maxZoom: 2,
  captureWheel: true,
});

// Should be called on unmount
canvas.destroy();

// Reset position and zoom to default values
canvas.reset();

// Manually update position and zoom
canvas.update({ z: 1.2 });
canvas.update((prev) => ({ z: prev.z + 0.2 }));

Frameworks & libraries

Contributing

Please read this documentation before contributing.

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.