Coder Social home page Coder Social logo

vue-panzoom's Introduction

vue-panzoom

This is a Vue.js port of panzoom, an extensible, mobile friendly pan and zoom framework (supports DOM and SVG).

Demo

Installation

Using npm

npm install vue-panzoom --save

Using yarn

yarn add vue-panzoom

Usage

main.js

// import Vuejs
import Vue from 'vue'
import App from './App.vue'

// import vue-panzoom
import panZoom from 'vue-panzoom'

// install plugin
Vue.use(panZoom);

new Vue({
  render: h => h(App),
}).$mount('#app')

App.vue

<template>
    <div id="app">
        <!-- apply to an image -->
        <panZoom>
            <img src="https://picsum.photos/300">
        </panZoom>

        <!-- apply to regular dom elements -->
        <panZoom>
            <p>You can zoom me</p>
        </panZoom>

        <!-- apply to svg -->
        <panZoom selector="#g1">
            <svg height="210" width="400">
                <g id="g1">
                    <path d="M150 0 L75 200 L225 200 Z" />
                </g>
            </svg>
        </panZoom>
    </div>
</template>

Changing the component's name

If you wish to change the name of the vue component from the default panZoom, you pass an option to the plugin like so:

Vue.use(panZoom, {componentName: 'yourPanZoom'});

and then use in your vue template like so:

<yourPanZoom></yourPanZoom>

Attributes

selector

Use this to specify an element within the scope of vue-panzoom component instance, to apply panZoom to. Default is the first root element of the vue-panzoom component. It accepts standard css selector specification.

<panZoom selector=".zoomable">
  <div class="not-zoomable">I cannot be zoomed and panned</div>
  <div class="zoomable">I can be zoomed and panned</div>
</panZoom>

Options

The options prop is used to define panzoom options. All panzoom options are supported

<panZoom :options="{minZoom: 0.5, maxZoom: 5}"></panZoom>

Events

You can listen to specific events in the lifecycle of a vue-panzoom instance. For example, in the code below the function onPanStart will be called when pan begins

<panZoom @panstart="onPanStart"></panZoom>

Another way to listen to events within the init event's callback, when you know for sure everything is ready and the panzoom instance is available. For example

<panZoom @init="onInit"></panZoom>
onInit: function(panzoomInstance, id) {
  panzoomInstance.on('panstart', function(e){
    console.log(e);
  });
}

init event

This event is fired when the vue-panzoom instance has been initialized successfully. For example:

<panZoom @init="onInit"></panZoom>

panzoom events

All events supported by panzoom are also supported here.

upgrading from 1.1.3 to 1.1.4

Version 1.1.4 uses "rollup-plugin-vue": "^6.0.0", which requires Vue 3. For projects using Vue 2, downgrade to 1.1.3, e.g.:

npm install [email protected]

vue-panzoom's People

Contributors

mistabiggx avatar dependabot[bot] avatar thecodealer avatar aesyondu avatar jonanvc avatar stuikomma 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.