欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue實現(xiàn)div滾輪放大縮小

 更新時間:2021年06月11日 11:10:21   作者:小城聽風雨  
這篇文章主要為大家詳細介紹了Vue實現(xiàn)div滾輪放大縮小,拖拽效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

Vue項目中實現(xiàn)div滾輪放大縮小,拖拽效果,類似畫布效果

1、引入插件vue-draggable-resizable,點我進入GitHub地址。

1)、npm install --save vue-draggable-resizable
2)、main.js文件中

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

3)、vue文件中使用

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)

// 拖拽·縮放·畫布插件
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文件: 只需要關注引入組件vue-draggable-resizable配置項和handleTableWheeltableZoom方法即可。

<template>
    <div class="is">
        <div
            style="height: 800px; width: 100%; border: 1px solid #000; position: relative; overflow: hidden;"
        >
            <!-- 引入組件. :lock-aspect-ratio="true":鎖定縱橫比例 :resizable="false": 不可縮放-->
            <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表格,無關緊要,任何div即可 -->
                    <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) {
            // 一開始默認是100%
            let zoom = parseInt(obj.style.zoom, 10) || 100;
            // 滾輪滾一下wheelDelta的值增加或減少120
            zoom += event.wheelDelta / 12;
            if (zoom > 0) {
                obj.style.zoom = zoom + "%";
            }
            return false;
        },
        // 單擊單元格事件(用于測試拖拽是否阻止了表格默認事件,無關緊要)
        handleCellClick(row) {
            this.$Message.info("你點擊了" + row.name);
        }
    }
};
</script>

<style scoped lang="less">
.is {
    .table {
        .name {
            cursor: pointer;
        }
    }
}
// iview表格樣式:iview官網(wǎng)復制就行,無關緊要
/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;
    }
}
// 去除畫布中div邊框
.vdr {
    border: none;
}
</style>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • 解決Vue-cli無法編譯es6的問題

    解決Vue-cli無法編譯es6的問題

    這篇文章主要介紹了解決Vue-cli無法編譯es6的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-10-10
  • Vue組件與生命周期詳細講解

    Vue組件與生命周期詳細講解

    Vue的生命周期就是vue實例從創(chuàng)建到銷毀的全過程,也就是new Vue() 開始就是vue生命周期的開始。Vue 實例有?個完整的?命周期,也就是從開始創(chuàng)建、初始化數(shù)據(jù)、編譯模版、掛載Dom -> 渲染、更新 -> 渲染、卸載 等?系列過程,稱這是Vue的?命周期
    2022-10-10
  • vue實現(xiàn)手機號碼抽獎上下滾動動畫示例

    vue實現(xiàn)手機號碼抽獎上下滾動動畫示例

    本篇文章主要介紹了vue實現(xiàn)手機號碼抽獎上下滾動動畫示例。具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • vue.js 初體驗之Chrome 插件開發(fā)實錄

    vue.js 初體驗之Chrome 插件開發(fā)實錄

    這篇文章主要介紹了vue.js 初體驗之Chrome 插件開發(fā)實錄 ,需要的朋友可以參考下
    2017-05-05
  • Vue鍵盤事件用法總結

    Vue鍵盤事件用法總結

    本篇文章主要介紹了Vue鍵盤事件用法總結,詳細的介紹了各種鍵盤事件的用法,有興趣的可以了解一下
    2017-04-04
  • vue項目通過a標簽下載圖片至zip包的示例代碼

    vue項目通過a標簽下載圖片至zip包的示例代碼

    在vue項目中,將圖片下載可使用流的形式,下載成單個圖片,或者將多個圖片下載至zip包,本文就是介紹使用a標簽下載圖片的用法,文中有詳細的代碼示例供大家參考,具有一定的參考價值,需要的朋友可以參考下
    2023-10-10
  • Vue中的 mixins 和 provide/inject詳解

    Vue中的 mixins 和 provide/inject詳解

    這篇文章主要介紹了Vue中的 mixins 和 provide/inject詳解,本文結合實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-07-07
  • vue如何獲取自定義元素屬性參數(shù)值的方法

    vue如何獲取自定義元素屬性參數(shù)值的方法

    這篇文章主要介紹了vue如何獲取自定義元素屬性參數(shù)值的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-05-05
  • vue-router 實現(xiàn)導航守衛(wèi)(路由衛(wèi)士)的實例代碼

    vue-router 實現(xiàn)導航守衛(wèi)(路由衛(wèi)士)的實例代碼

    這篇文章主要介紹了vue-router 實現(xiàn)導航守衛(wèi)(路由衛(wèi)士)的實例代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-09-09
  • 如何理解Vue中computed和watch的區(qū)別

    如何理解Vue中computed和watch的區(qū)別

    這篇文章主要介紹了Vue中computed和watch的區(qū)別,對Vue感興趣的同學,可以參考下
    2021-05-05

最新評論