Giter VIP home page Giter VIP logo

polymer-panzoom's Introduction

polymer-panzoom

Panning/zooming web component utilizing CSS3 transforms, built with Polymer

View Live Example

See a live example here. Drag the image or use arrow keys to pan and use the mouse scroll wheel to zoom.

Run the Demo

npm install
npm start

Then navigate a browser to http://localhost:8080/

Usage

Setting up Dependencies

Serve Polymer at root, i.e. /polymer.

The web-components polyfill is required by Polymer, so ensure that it's included, for example with a <script> tag:

<script src="webcomponentsjs/webcomponents-lite.min.js"></script>

If using polymer-panzoom as a bower component, the contents of the bower components directory could be served at root, such that /polymer /webcomponentsjs are accesible.

Using the Component

Import polymer-panzoom with a <link> tag:

<link rel="import" href="panzoom.html">

polymer-panzoom elements can now be used in the page to wrap other elements for panning/zooming. For example:

<polymer-panzoom id="my-panzoom">
  <img src="big-image-to-be-zoomed-and-panned.jpg">
</polymer-panzoom>

Panning/zooming parameters can then be applied, for example:

var myPanzoom = document.getElementById('my-panzoom');
myPanzoom.panOffset({x: 100, y: 150});
myPanzoom.zoomOffset(0.1);

Methods

.panzoom(options)

Apply panning/zooming parameters.

options - An object containing:

  • translate {x, y}
  • scale (multiplier)

.panzoomTowardPosition(position, zoomOffset)

Pan and zoom toward or away from the given position based on a zoom offset factor.

  • position {x, y}
  • zoomOffset multiplier

.panzoomShowRegion(rect, minimumZoom)

Pan and zoom to fit the given rectangle into view.

  • rect {left, top, right, bottom}
  • minimumZoom (optional)

.panzoomConvertPoint(point, sourceCoords, destCoords)

Translates an X-Y pixel position to/from container and content coordinates. Container coordinates are local to the DOM element on which this panzoom behavior is applied. Content coordinates are local to the child elements within the panzoom DOM element.

  • point An object with x and y fields, e.g. {x:100, y:20.5}
  • sourceCoords Source coordinates, either "CONTAINER" or "CONTENT".
  • destCoords Destination coordinates, either "CONTAINER" or "CONTENT".

Returns: The converted point, as an object with x and y fields, e.g. {x:40.89, y:42}

polymer-panzoom's People

Contributors

shone 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.