简体   繁体   中英

How to implement zoomIn and zoomout in vue-panzoom

I am trying to implement vue-panzoom 's manual zoom option. panzoom is the parent library and the

default zoom which is well demoed here is what i am trying to acheive https://timmywil.com/panzoom/demo/#Panning%20and%20zooming

As per the original library ( panzoom ), there are zoom,zoomIn and zoomOut functions,

but the instance does not have those methods

在此处输入图像描述

the only way i could find till now is using smooth zoom function,and i am not sure how to use it

this.$refs.panZoom.$panZoomInstance.smoothZoom(2.2);

This what i have tried till now

https://codesandbox.io/s/poc-zoompan-dz70x?file=/src/App.vue:737-793 Please take a look at it,any suggestions would be helpful.

You can see here a simply implementation of timmywil panzoom library you can easly use props and slot to create your own component reusable in all of your project

<template>
    <div>
        <div class="command">
            <button @click="zoom(1)">ZoomIn</button>
            <button @click="zoom(-1)">ZoomOut</button>
        </div>
        <div style="overflow: hidden;">
            <div id="panzoom-element">
                <img src="https://picsum.photos/300">
            </div>
        </div>
    </div>
</template>
<script>
import Panzoom from '@panzoom/panzoom'

export default {
    props: {
        options: {type: Object, default: () => {}},
    },
    mounted() {
        this.panzoom = Panzoom(document.getElementById('panzoom-element'), {
            maxScale: 5
        })
    },
    methods : {
        zoom(level){
            level === -1 ? this.panzoom.zoomOut() : this.panzoom.zoomIn()
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM