Introduction

Tiny and high performance zoom and pan library for Vue 3. It uses CSS Transforms which provides hardware acceleration.

Checkout the demosopen in new window.

Features

  • Simply wrap your content in VueZoomable component to make it zoom-able and pan-able.
  • Mouse wheel support
  • Touch and pinch-zoom support
  • Control buttons for zoom and pan
  • Supports SVG and HTML content
  • Uses CSS transform for zoom and pan
  • ScrollOverlay component to lock pan/zoom while scrolling

Installation

npm install vue-zoomable

Usage

Immediate child of VueZoomable must be either svg or an html container.

<template>
  <VueZoomable
    style="width: 500px; height: 500px; border: 1px solid black"
    selector="#myContent"
    :minZoom="0.5"
    :maxZoom="3"
  >
    <svg>
      <g id="myContent">
        <circle x="10" y="10" r="50" />
      </g>
    </svg>
  </VueZoomable>
</template>

<script setup lang="ts">
import VueZoomable from "vue-zoomable";
import "vue-zoomable/dist/style.css";
</script>

API Reference

VueZoomable

Props

NametypedefaultDescription
selectorstring* > *Root element to apply transform on. Preferrably an id on <div> or <g> tag
maxZoomnumber3Maximum allowed zoom
minZoomnumber0.5Minimum allowed zoom
dblClickZoomStepnumber0.4Step size for zoom on double click
wheelZoomStepnumber0.2Step size for zoom on wheel
panEnabledbooleantrueEnable panning
zoomEnabledbooleantrueEnable zoom
mouseEnabledbooleantrueEnable mouse events
touchEnabledbooleantrueEnable touch events
dblClickEnabledbooleantrueZoom on double click enabled
wheelEnabledbooleantrueZoom on mouse enabled
initialZoomnumber0.5(Deprecated) Initial zoom value. Use v-model:zoom
initialPanXnumber0(Deprecated) Initial pan along x-axis. Use v-model:pan
initialPanYnumber0(Deprecated) Initial pan along y-axis. Use v-model:pan
enableControlButtonbooleantrueEnable or disable control buttons
buttonPanStepnumber15Step size for pan on control buttons
buttonZoomStepnumber0.1Step size for pan on control buttons

Model

  • v-model:zoom
  • v-model:pan

Slots

  • default - Default Content
  • buttons - Control buttons

Events

  • panned
  • zoom

All events have argument of type ZoomableEvent.

ZoomableEvent

FieldTypeDescription
zoomnumberCurrent zoom value
panobjectCurrent pan value and delta change in case of panned event.
typestringSource type which triggered the event. dblClick, mouse, touch, wheel or control-btn.

Sample event data:

{
  "zoom": 0.3,
  "pan": {
    "x": 100,
    "y": 2,
    "deltaX": 0,
    "deltaY": 2
  },
  "type": "mouse"
}

ScrollOverlay

Prevents mistaken zoom/pan while scrolling the page using mouse wheel or touchscreen. Useful if your zoomable content is embedded within scrollable content. Google map provides similar functionality Googleopen in new window.

Props

NametypedefaultDescription
wheelUnlockKeystringControlWheel is disabled, until the corresponding Key is pressed. You can set it to any value of event.key. see here
enableWheelLockbooleantrueWhen true, zoom using wheel is disabled until wheelUnclockKey is pressed.
enableTouchLockbooleantrueWhen true, pan or zoom requires touch using two fingers.

Contribute

Contributions are most welcome. Please follow the below steps for any contributions.

If you add new feature

  • Open a suggestion issue first.
  • Provide your reasoning on why you want to add this feature.
  • Submit your PR.

If you fix a bug

  • If you are resolving an issue, please add fix: #<issue number> <short message> in your PR title (e.g.fix: #3899 update entities encoding/decoding).
  • Provide a description of the bug in your PR and/or link to the issue.

Setup

The setup is pretty easy. You need to have pnpm installed.

# install the dependencies
pnpm i

# start the dev thingie
pnpm run dev

Where should I start?

A good way to start is to find an issue labeled as bug, help wanted or feature request and suggest your approach in comments.

Other ways to help:

  • Write tests
  • Documentation & Demos
  • Share your thoughts! Any features you thing vue-zoomable is missing? Any suggestions? Would love to hear that.

Acknowledgements

Last Updated:
Contributors: Hassaan Akbar, Hassan Akbar