Code Monkey home page Code Monkey logo

mouse-zoom's Introduction

Vue

Vue Mouse Zoom

Vue3-based Vue scales and drags components according to mouse position.

license Awesome

English | 简体中文

Demo

demp

Feature

Zoomable

  • Support to zoom according to the mouse position when the wheel is scrolling, which can zoom in on a certain point.
  • Support for mac touchpad scaling.

Draggable

  • The components pan when the mouse wheel is scrolled, and the multi-directional translation effect can be carried out when mac uses the touchpad.
  • The component can drag and drop when the left button is pressed.

Support for Typescript

Components are written in TypeScript, so they are naturally type-friendly.

Install

npm package

// npm
npm install vue-mouse-zoom

// yarn
yarn add vue-mouse-zoom

// pnpm
pnpm add vue-mouse-zoom

Example

<script setup lang="ts">
import { VueMouseZoom } from 'vue-mouse-zoom';
</script>

<template>
  <div style="width: 300px; height: 300px;">
    <VueMouseZoom>
      <img
        src="https://avatars.githubusercontent.com/u/68246760?v=4"
        style="width: 200px; height: 200px"
      />
    </VueMouseZoom>
  </div>
</template>

Notice 📢

Nodes wrapped by the VueMouseZoom component must specify width and height, and may not use variable width and height such as 100% !

Props

props Introduction default required
zoom The magnification of the component zoom, which is limited by the values of max- zoom and min- zoom when rendering for the first time 1 false
min-zoom Minimum magnification on first rendering 0.05 false
max-zoom The maximum scale of the first rendering 4 false
is-center Whether to center when rendering for the first time 中 true false
is-draggable Is dragging allowed? true false
zoom-handle The processing function when zooming, which returns a scale (e: WheelEvent, preScale: number) => number false

Slot

name introduction params how to use
default The default slot of the component, and the content will be placed inside the component isWheel: boolean When there is a performance problem in the process of scaling and dragging a component, you can use this parameter to remove the dom optimization performance within the component.

Event

name introduction params how to use
on-zoom-update This event is triggered when the zoom ratio changes scale:number The current magnification can be obtained based on this event

Browser compatibility

Consistent with Vue3 support

mouse-zoom's People

Contributors

zhaoyuqiqi avatar

Stargazers

 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.