Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kirillmurashov/vue-drag-resize
Vue2 && Vue3 Component for resize and drag elements
https://github.com/kirillmurashov/vue-drag-resize
component drag draggable resizable resize vue vuejs
Last synced: 30 days ago
JSON representation
Vue2 && Vue3 Component for resize and drag elements
- Host: GitHub
- URL: https://github.com/kirillmurashov/vue-drag-resize
- Owner: kirillmurashov
- License: mit
- Created: 2018-04-26T16:10:41.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-31T03:19:46.000Z (over 1 year ago)
- Last Synced: 2024-10-08T07:08:54.733Z (about 1 month ago)
- Topics: component, drag, draggable, resizable, resize, vue, vuejs
- Language: JavaScript
- Homepage: https://kirillmurashov.com/vue-drag-resize/
- Size: 3.02 MB
- Stars: 2,246
- Watchers: 22
- Forks: 325
- Open Issues: 102
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Vue-drag-resize
[![Latest Version on NPM](https://img.shields.io/npm/v/vue-drag-resize.svg?style=flat-square)](https://npmjs.com/package/vue-drag-resize)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![npm](https://img.shields.io/npm/dt/vue-drag-resize.svg?style=flat-square)](https://www.npmjs.com/package/vue-drag-resize)> Vue Component for draggable and resizable elements.
## Table of Contents
* [Features](#features)
* [Install and basic usage](#install-and-basic-usage)
* [Props](#props)
* [Events](#events)
* [Contributing](#contributing)
* [License](#license)### Demo
[Demo](http://kirillmurashov.com/vue-drag-resize)
### Features
* A lightweight, no-dependency
* All props are reactive
* Support touch events
* Snap element to custom grid
* Use draggable, resizable or both
* Define sticks for resizing
* Save aspect ratio for resizable components
* Restrict size and movement to parent element
* Restrict drag to vertical or horizontal axis## Install and basic usage
```bash
$ npm i -s vue-drag-resize
```Register the component:
```js
import Vue from 'vue'
import VueDragResize from 'vue-drag-resize'Vue.component('vue-drag-resize', VueDragResize)
```Use the component:
```vue
Hello World!
{{ top }} х {{ left }}
{{ width }} х {{ height }}
import VueDragResize from 'vue-drag-resize';
export default {
name: 'app',components: {
VueDragResize
},data() {
return {
width: 0,
height: 0,
top: 0,
left: 0
}
},methods: {
resize(newRect) {
this.width = newRect.width;
this.height = newRect.height;
this.top = newRect.top;
this.left = newRect.left;
}
}
}```
### Props
#### isActive
Type: `Boolean`
Required: `false`
Default: `false`Determines whether the component should be active.
确定组件是否应处于活动状态。
```html
```
#### preventActiveBehavior
Type: `Boolean`
Required: `false`
Default: `false`Disable behavior of the component by clicking on it and clicking outside the component's area (isActive: true / false).
If the prop is enabled, the component is oriented only to the specified.通过单击组件并单击组件区域外部来禁用组件的行为(isActive:true / false)。
如果启用了prop,则组件仅面向指定的。```html
```
#### parentW
Type: `Number`
Required: `false`
Default: `0`Define the initial width of the parent element. If not specified it calculated automatically.
With this parameter, you can set the bounding area for the component, and also it is used when resizing in real time.定义父元素的初始宽度。 如果未指定,则自动计算。
使用此参数,您可以设置组件的边界区域,并在实时调整大小时使用它。
```html```
#### parentH
Type: `Number`
Required: `false`
Default: `0`Define the initial height of the parent element. If not specified it calculated automatically.
With this parameter, you can set the bounding area for the component, and also it is used when resizing in real time.定义父元素的初始高度。 如果未指定,则自动计算。
使用此参数,您可以设置组件的边界区域,并在实时调整大小时使用它。```html
```
#### parentScaleX
Type: `Number`
Required: `false`
Default: `1`Define the initial horizontal scale or the parent element. Same value in parent's transform: scale() css definition.
The drag/resize and the sticks' sizes will computed with this value.定义初始水平比例或父元素。父级的transform:scale()css定义中的值相同。
拖动/调整大小和杆的大小将使用该值计算。
```html```
#### parentScaleY
Type: `Number`
Required: `false`
Default: `1`Define the initial vertical scale or the parent element. Same value in parent's transform: scale() css definition.
The drag/resize and the sticks' sizes will computed with this value.定义初始垂直比例或父元素。父级的transform:scale()css定义中的值相同。
拖动/调整大小和杆的大小将使用该值计算。```html
```
#### isDraggable
Type: `Boolean`
Required: `false`
Default: `true`Determines whether the component should draggable.
确定组件是否应可拖动。
```html
```
#### isResizable
Type: `Boolean`
Required: `false`
Default: `true`Determines whether the component should resize.
确定组件是否应调整大小。
```html
```
#### parentLimitation
Type: `Boolean`
Required: `false`
Default: `false`Limits the scope of the component's change to its parent size.
将组件更改的范围限制为其父大小。
```html
```
#### snapToGrid
Type: `Boolean`
Required: `false`
Default: `false`Determines whether the component should move and resize in predefined steps.
```html
```
#### gridX
Type: `Number`
Required: `false`
Default: `50`Define the grid step size for the horizontal axis. Both sides of the component (left and right) will snap to this step.
```html
```
#### gridY
Type: `Number`
Required: `false`
Default: `50`Define the grid step size for the vertical axis. Both sides of the component (top and bottom) will snap to this step.
```html
```
#### aspectRatio
Type: `Boolean`
Required: `false`
Default: `false`Determines whether the component should retain its proportions.
确定组件是否应保持其比例。
```html
```
#### w
Type: `Number|String`
Required: `false`
Default: `200`Define the initial width of the component.
The value can either be a number >= 0 or the string 'auto'.
If set to 'auto', the initial width value will be equal to the width of the content within the component.定义组件的初始宽度。
```html
```
#### h
Type: `Number|String`
Required: `false`
Default: `200`Define the initial height of the component.
The value can either be a number >= 0 or the string 'auto'.
If set to 'auto', the initial height value will be equal to the height of the content within the component.定义组件的初始高度。
```html
```
#### minw
Type: `Number`
Required: `false`
Default: `50`Define the minimal width of the component.
定义组件的初始宽度。
```html
```
#### minh
Type: `Number`
Required: `false`
Default: `50`Define the minimal height of the component.
定义组件的最小高度。
```html
```
#### x
Type: `Number`
Required: `false`
Default: `0`Define the initial x position of the component.
定义组件的初始X位置。
```html
```
#### y
Type: `Number`
Required: `false`
Default: `0`Define the initial y position of the component.
定义组件的初始Y位置。
```html
```
#### z
Type: `Number|String`
Required: `false`
Default: `auto`Define the zIndex of the component.
定义组件的zindex(层级)。
```html
```
#### stickSize
Type: `Number`
Required: `false`
Default `8`Define the sticks' size.
```html
```
#### sticks
Type: `Array`
Required: `false`
Default: `['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml']`Define the array of handles to restrict the element resizing:
定义句柄数组以限制元素大小调整:
* `tl` - Top left
* `tm` - Top middle
* `tr` - Top right
* `mr` - Middle right
* `br` - Bottom right
* `bm` - Bottom middle
* `bl` - Bottom left
* `ml` - Middle left```html
```
#### axis
Type: `String`
Required: `false`
Default: `both`Define the axis on which the element is draggable. Available values are `x`, `y`, `both` or `none`.
定义元素可拖动的轴。 可用值为`x`,`y`,`both`或`none`。
```html
```
#### dragHandle
Type: `String`
Required: `false`Defines the selector that should be used to drag the component.
定义应该用于拖动组件的选择器。
```html
```
#### dragCancel
Type: `String`
Required: `false`Defines a selector that should be used to prevent drag initialization.
定义应该用于防止拖动初始化的选择器。
```html
```
#### contentClass
Type: `String`
Required: `false`Defines a class that is applied on the div with the class vdr
```html
```
---
### Events
#### clicked
Required: `false`
Parameters: `Original event handler`Called whenever the component gets clicked.
单击组件时调用。
```html
```
#### activated
Required: `false`
Parameters: `-`Called whenever the component gets clicked, in order to show handles.
单击组件时调用,以显示句柄。
```html
```
#### deactivated
Required: `false`
Parameters: `-`Called whenever the user clicks anywhere outside the component, in order to deactivate it.
每当用户单击组件外部的任何位置时调用,以便将其停用。
```html
```
#### resizing
Required: `false`
Parameters: `object````javascript
{
left: Number, //the X position of the component
top: Number, //the Y position of the component
width: Number, //the width of the component
height: Number //the height of the component
}
```Called whenever the component gets resized.
每当组件调整大小时调用。
```html
```
#### resizestop
Required: `false`
Parameters: `object`
```javascript
{
left: Number, //the X position of the component
top: Number, //the Y position of the component
width: Number, //the width of the component
height: Number //the height of the component
}
```Called whenever the component stops getting resized.
每当组件停止调整大小时调用。
```html
```
#### dragging
Required: `false`
Parameters: `object`
```javascript
{
left: Number, //the X position of the component
top: Number, //the Y position of the component
width: Number, //the width of the component
height: Number //the height of the component
}
```Called whenever the component gets dragged.
每当拖动组件时调用。
```html
```
#### dragstop
Required: `false`
Parameters: `object`
```javascript
{
left: Number, //the X position of the component
top: Number, //the Y position of the component
width: Number, //the width of the component
height: Number //the height of the component
}
```Called whenever the component stops getting dragged.
每当组件停止拖动时调用。
```html
```
## Contributing
Any contribution to the code or any part of the documentation and any idea and/or suggestion are very welcome.
``` bash
# serve with hot reload at localhost:8081
npm run start# distribution build
npm run build```
## License
[MIT license](LICENSE)