Vue implements div wheel zooming in and out

Vue implements div wheel zooming in and out

Implement div wheel zooming in and out in Vue project, drag effect, similar to canvas effect

1. Import the vue-draggable-resizable plug-in and click here to enter the GitHub address.

1), npm install --save vue-draggable-resizable
2) In the main.js file

import VueDraggableResizable from 'vue-draggable-resizable'
import 'vue-draggable-resizable/dist/VueDraggableResizable.css'
Vue.component('vue-draggable-resizable', VueDraggableResizable)

3) Use in vue file

main.js:

import Vue from 'vue'
import App from './App'
import router from './router'
Vue.config.productionTip = false

// iview
import ViewUI from 'view-design';
import 'view-design/dist/styles/iview.css';
Vue.use(ViewUI)

// Drag, zoom, canvas plugin import VueDraggableResizable from 'vue-draggable-resizable'
import 'vue-draggable-resizable/dist/VueDraggableResizable.css'
Vue.component('vue-draggable-resizable', VueDraggableResizable)

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

vue file: Just focus on introducing the vue-draggable-resizable component configuration item and the handleTableWheel and tableZoom methods.

<template>
    <div class="is">
        <div
            style="height: 800px; width: 100%; border: 1px solid #000; position: relative; overflow: hidden;"
        >
            <!-- Import components. :lock-aspect-ratio="true": lock aspect ratio:resizable="false": non-scalable -->
            <vue-draggable-resizable
                w="auto"
                h="auto"
                :grid="[20,40]"
                :x="10"
                :y="10"
                :resizable="false"
            >
                <div class="table" ref="table" @wheel.prevent="handleTableWheel($event)">
                 <-- iview table, doesn't matter, any div will do -->
                    <Table
                        :columns="columns1"
                        :data="data1"
                        size="small"
                        :disabled-hover="true"
                        border
                    >
                        <template slot-scope="{ row, index }" slot="name">
                            <Tooltip :content="row.name" placement="top" transfer>
                                <span class="name" @click="handleCellClick(row)">{{ row.name }}</span>
                            </Tooltip>
                        </template>
                    </Table>
                </div>
            </vue-draggable-resizable>
        </div>
    </div>
</template>

<script>
import VueDraggableResizable from "vue-draggable-resizable";
export default {
    name: "is",
    data() {
        return {
            columns1: [
                {
                    title: "Name",
                    slot: "name",
                    width: 120
                },
                {
                    title: "Age",
                    key: "age",
                    width: 120
                },
                {
                    title: "Address",
                    key: "address",
                    width: 120
                },
                {
                    title: "Name",
                    key: "name",
                    width: 120
                },
                {
                    title: "Age",
                    key: "age",
                    width: 120
                },
                {
                    title: "Address",
                    key: "address",
                    width: 120
                },
                {
                    title: "Name",
                    key: "name",
                    width: 120
                },
                {
                    title: "Age",
                    key: "age",
                    width: 120
                },
                {
                    title: "Address",
                    key: "address",
                    width: 120
                }
            ],
            data1: [
                {
                    name: "John Brown",
                    age: 18,
                    address: "New York No. 1 Lake Park"
                },
                {
                    name: "Jim Green",
                    age: 25,
                    address: "London No. 1 Lake Park",
                    cellClassName: {
                        age: "demo-table-info-cell-age",
                        address: "demo-table-info-cell-address"
                    }
                },
                {
                    name: "Joe Black",
                    age: 30,
                    address: "Sydney No. 1 Lake Park"
                },
                {
                    name: "Jon Snow",
                    age: 26,
                    address: "Ottawa No. 2 Lake Park",
                    cellClassName: {
                        name: "demo-table-info-cell-name"
                    }
                },
                {
                    name: "John Brown",
                    age: 18,
                    address: "New York No. 1 Lake Park"
                },
                {
                    name: "Jim Green",
                    age: 25,
                    address: "London No. 1 Lake Park",
                    cellClassName: {
                        age: "demo-table-info-cell-age",
                        address: "demo-table-info-cell-address"
                    }
                },
                {
                    name: "Joe Black",
                    age: 30,
                    address: "Sydney No. 1 Lake Park"
                },
                {
                    name: "Jon Snow",
                    age: 26,
                    address: "Ottawa No. 2 Lake Park",
                    cellClassName: {
                        name: "demo-table-info-cell-name"
                    }
                }
            ]
        };
    },
    mounted() {},
    methods: {
        handleTableWheel(event) {
            let obj = this.$refs.table;
            return this.tableZoom(obj, event);
        },
        tableZoom(obj, event) {
            // The default is 100% at the beginning
            let zoom = parseInt(obj.style.zoom, 10) || 100;
            //Roll the wheel once and the value of wheelDelta increases or decreases by 120
            zoom += event.wheelDelta / 12;
            if (zoom > 0) {
                obj.style.zoom = zoom + "%";
            }
            return false;
        },
        // Click cell event (used to test whether dragging blocks the table's default event, which is irrelevant)
        handleCellClick(row) {
            this.$Message.info("You clicked" + row.name);
        }
    }
};
</script>

<style scoped lang="less">
.is {
    .table {
        .name {
            cursor: pointer;
        }
    }
}
// iview table style: just copy from iview official website, it doesn't matter/deep/ .ivu-table {
    .demo-table-info-row td {
        background-color: #2db7f5;
        color: #fff;
    }
    td.demo-table-info-column {
        background-color: #2db7f5;
        color: #fff;
    }
    .demo-table-error-row td {
        background-color: #ff6600;
        color: #fff;
    }
    .demo-table-info-cell-name {
        background-color: #2db7f5;
        color: #fff;
    }
    .demo-table-info-cell-age {
        background-color: #ff6600;
        color: #fff;
    }
    .demo-table-info-cell-address {
        background-color: #187;
        color: #fff;
    }
}
// Remove the div border in the canvas.vdr {
    border: none;
}
</style>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue implements zoom in, zoom out and drag function
  • Vue uses svg files to supplement -svg zoom in and out operations (using d3.js)
  • Vue.js+Echarts development chart zoom in and out function example
  • Detailed explanation of the use of Vue image drag and drop zoom component

<<:  VirtualBox CentOS7.7.1908 Python3.8 build Scrapy development environment [graphic tutorial]

>>:  MySQL 8.0.13 decompression version installation graphic tutorial under Windows

Recommend

Vue implements fuzzy query-Mysql database data

Table of contents 1. Demand 2. Implementation 3. ...

Tutorial on installing lamp-php7.0 in Centos7.4 environment

This article describes how to install lamp-php7.0...

MySQL fuzzy query usage (regular, wildcard, built-in function)

Table of contents 1. MySQL wildcard fuzzy query (...

HTML Tutorial: Unordered List

<br />Original text: http://andymao.com/andy...

What to do if the online MySQL auto-increment ID is exhausted

Table of contents Table definition auto-increment...

Linux kernel device driver system call notes

/**************************** * System call******...

Sample code for installing ASPNET.Core3.0 runtime in Linux

# The following examples are for x64-bit runtime ...

Analysis of the Principle and Method of Implementing Linux Disk Partition

remember: IDE disk: the first disk is hda, the se...

CSS sets Overflow to hide the scroll bar while allowing scrolling

CSS sets Overflow to hide the scroll bar while al...

How to view and optimize MySql indexes

MySQL supports hash and btree indexes. InnoDB and...

How to use Nginx to realize the coexistence of multiple containers in the server

background There is a Tencent Linux cloud host, o...

How to split data in MySQL table and database

Table of contents 1. Vertical (longitudinal) slic...

Vue complete code to implement single sign-on control

Here is a Vue single sign-on demo for your refere...

Summary of three rules for React state management

Table of contents Preface No.1 A focus No.2 Extra...