vue设置div大小(Vue实现div滚轮放大缩小)
类别:编程学习 浏览量:493
时间:2022-01-19 00:29:29 vue设置div大小
Vue实现div滚轮放大缩小Vue项目中实现li滚轮放大缩小,拖拽效果,类似画布效果
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配置项和handleTableWheel、tableZoom方法即可。
<template> <li class="is"> <li 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" > <li class="table" ref="table" @wheel.prevent="handleTableWheel($event)"> <-- iview表格,无关紧要,任何li即可 --> <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> </li> </vue-draggable-resizable> </li> </li> </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官网复制就行,无关紧要 /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; } } // 去除画布中li边框 .vdr { border: none; } </style>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持开心学习网。
您可能感兴趣
- vue监控对象变化(Vue之监听方法案例详解)
- vue 中后台管理系统(Vue实现学生管理功能)
- vue实现一个炫酷的日历组件(vue利用Moment插件格式化时间的实例代码)
- vue身份验证(详解vue身份认证管理和租户管理)
- vueclass和style绑定(Vue中Class和Style实现v-bind绑定的几种用法)
- vue创建项目同时引入elementui(Vue Element前端应用开发之开发环境的准备工作)
- vue源码系列教程(vue使用引用库中的方法附源码)
- vue element 权限管理(Vue Element前端应用开发之功能点管理及权限控制)
- vue商城购物车数据(vue实现购物车全部功能的简单方法)
- mongovue的使用
- vue中的mapgetter优势(vuex 中辅助函数mapGetters的基本用法详解)
- vue手动清除keepalive缓存(vue中keep-alive组件的用法示例)
- vue树形表格内容太长(VUE 无限层级树形数据结构显示的实现)
- vue中如何判断请求状态码(关于VUE的编译作用域及slot作用域插槽问题)
- vue界面自动生成(Vue中实现3D标签云的详细代码)
- vue怎么更换自定义水印(Vue之全局水印的实现示例)
- 小米推出米兔儿童电话手表奥特曼版,799 元,支持微信 QQ(小米推出米兔儿童电话手表奥特曼版)
- 贾怀胤唱《白龙马》 炸场 了 没想到京剧还能这么玩(贾怀胤唱白龙马)
- 白龙马的改编学生版,快来看看(白龙马的改编学生版)
- 萌娃唱《白龙马》走红,那生动的小表情,网友直呼 简直是戏精(萌娃唱白龙马走红)
- 朱鹤松被不断认可,凤凰传奇玲花喊话岳云鹏,索要老朱演出门票(朱鹤松被不断认可)
- 元宵晚会槽点多,芒果台上来就假唱,岳云鹏不说相声改评书了(元宵晚会槽点多)
热门推荐
- python元组汇总(Python数据类型之Tuple元组实例详解)
- MongoDB中的索引的操作
- mysql表结构设计分享(MySql开发之自动同步表结构)
- vue 表格数据增加修改(vue element实现表格增加删除修改数据)
- sqlserver拒绝访问怎么办(SQL server服务显示远程过程调用失败的解决方法)
- ASP.NET URL路径问题
- html输入框的宽度怎么设置(html如何对span设置宽度)
- 如何编写错误日志才更容易排查问题
- docker 运行容器命令详细参数详解(Docker Hub运行原理及实现过程解析)
- docker容器启动失败怎么查找原因(解决docker容器启动后马上退出的问题)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9