自由拖动缩放组件.
- 没有依赖包
- 可以拖动 位置 和 大小
- 可以设定大小调整范围
- 可以限制元素只能在父组件内拖动
- 可以自定义网格
- 可以限制元素只能水平 或 竖直拖动
- 方向键可以微调坐标
$ npm install --save deformation注册组件
import Vue from 'vue'
import deformation from 'deformation'
Vue.component('Deformation', deformation)使用组件
<template>
<div style="height: 500px; width: 500px; border: 1px solid red; position: relative;">
<Deformation :w="100" :h="100" v-on:dragging="onDrag" v-on:resizing="onResize" :parent="true">
<p>Hello! I'm a flexible component. You can drag me around and you can resize me.<br>
X: {{ x }} / Y: {{ y }} - Width: {{ width }} / Height: {{ height }}</p>
</Deformation>
</div>
</template>
<script>
import Deformation from 'deformation'
export default {
data: function () {
return {
width: 0,
height: 0,
x: 0,
y: 0
}
},
methods: {
onResize: function (x, y, width, height) {
this.x = x
this.y = y
this.width = width
this.height = height
},
onDrag: function (x, y) {
this.x = x
this.y = y
}
}
}
</script>类型: Boolean
必要性: false
默认值: true
定义组件是否可以拖动.
<Deformation :draggable="false">类型: Boolean
必要性: false
默认值: true
定义组件是否可以调整大小.
<Deformation :resizable="false">类型: Number
必要性: false
默认值: 200
定义组件的初始宽度.
<Deformation :w="200">类型: Number
必要性: false
默认值: 200
定义组件的初始高度.
<Deformation :h="200">类型: Number
必要性: false
默认值: 50
定义组件的最小宽度.
<Deformation :minw="50">类型: Number
必要性: false
默认值: 50
定义组件的最小高度.
<Deformation :minh="50">类型: Number
必要性: false
默认值: 0
定义组件初始横轴坐标.
<Deformation :x="0">类型: Number
必要性: false
默认值: 0
定义组件初始纵轴坐标.
<Deformation :y="0">类型: Array
必要性: false
默认值: ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml']
Define the array of handles to restrict the element resizing:
tl- Top lefttm- Top middletr- Top rightmr- Middle rightbr- Bottom rightbm- Bottom middlebl- Bottom leftml- Middle left
<Deformation :handles="['tm','bm','ml','mr']">类型: String
必要性: false
默认值: both
定义组件可以拖动的轴线. 有效值为: x, y, both.
<Deformation :axis="x">类型: Array
必要性: false
默认值: [1,1]
定义组件网格.
<Deformation :grid="[1,1]">类型: Boolean
必要性: false
默认值: false
限制元素移动的速度以及维度.
<Deformation :parent="true">必要性: false
Parameters: -
组件被初始化事件.
<Deformation @activated="onActivated">必要性: false
Parameters: -
组件被销毁事件.
<Deformation @deactivated="onDeactivated">必要性: false
Parameters:
left组件 X 轴坐标top组件 Y 轴坐标width组件宽度height组件高度
组件大小改变事件.
<Deformation @resizing="onResizing">必要性: false
Parameters:
left组件 X 轴坐标top组件 Y 轴坐标width组件宽度height组件高度
组件大小改变结束事件.
<Deformation @resizestop="onResizstop">必要性: false
Parameters:
left组件 X 轴坐标top组件 Y 轴坐标
组件拖动事件.
<Deformation @dragging="onDragging">必要性: false
Parameters:
left组件 X 轴坐标top组件 Y 轴坐标
组件拖动结束事件.
<Deformation @dragstop="onDragstop">