1.0.12 • Published 4 months ago

svg-zoom-drag-vue-directives v1.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

EN/中文

Custom vue directives

Provide two Vue custom directives that are compatible with Vue 2 and Vue 3.

The first directive allows the user to control the zoom in and out of an SVG image using the mouse wheel.

The second directive allows the user to drag the SVG image by holding down the mouse and moving the cursor.

This is achieved by adjusting the viewbox attribute of the SVG.

demo

github pages: https://zqy233.github.io/svg-zoom-drag-vue-demo/#/

code: https://github.com/zqy233/svg-zoom-drag-vue-demo

Usage

npm i -s svg-zoom-drag-vue-directives

Vue2

import Vue from "vue";
import App from "./App.vue";

import { svgWheel, svgDrag } from "svg-zoom-drag-vue-directives";
svgWheel(Vue);
svgDrag(Vue);

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

Vue3

import { createApp } from "vue";
import App from "./App.vue";

import { svgWheel, svgDrag } from "svg-zoom-drag-vue-directives";
const app = createApp(App);
svgWheel(app);
svgDrag(app);

app.mount("#app");
<template>
  <div id="svg" v-html="svgString" v-svgWheel v-svgDrag></div>
</template>
<script setup lang="ts">
import { svgText } from "./svgText";
const svgString = ref("");
onMounted(() => {
  svgString.value = svgText;
});
</script>
<style>
* {
  margin: 0;
  padding: 0;
}
#svg {
  width: 100%;
  height: 100vh;
  overflow: hidden;
}
svg {
  width: 100% !important;
  height: 100% !important;
  user-select: none;
}
</style>

Note

This directive binds the first child element of the element to which it is attached as an SVG. So please be careful when binding the element.

const svgDom = el.firstChild as SVGSVGElement;

This design is intended to be used with v-html.

<div id="svg" v-html="svgString" v-svgWheel v-svgDrag></div>
1.0.12

4 months ago

1.0.9

11 months ago

1.0.11

11 months ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago