<p align="center"> <img src="https://github.com/2json/react-draggable-resizable/blob/master/assets/logo.png" /> </p>
npm install react-draggable-resizable


> React Component for draggable and resizable component
使用npm
``bash`
npm install react-draggable-resizable --save
使用yarn
`bash`
yarn add react-draggable-resizable
`jsx
import React from 'react'
import ReactDOM from 'react-dom'
import ReactDraggableResizable from 'react-draggable-resizable'
class App extends React.Component {
constructor(props) {
super(props)
this.state = {
width: 0,
height: 0,
left: 0,
right: 0
}
}
onDrag(left, top) {
this.setState({
left,
top
})
}
onResize(left, top, width, height) {
this.setState({
left,
top,
width,
height
})
}
render() {
const { left, top, width, height } = this.state
return (
h={200}
dragging={this.onDrag.bind(this)}
resizing={this.onResize.bind(this)}
>
ReactDOM.render(
`
##### active
- Type: Booleanfalse
- Required: false
- Default:
用于控制组件的状态
`jsx`
##### draggable
- Type: Booleanfalse
- Required: true
- Default:
控制组件是否能够拖动
`jsx`
##### resizable
- Type: Booleanfalse
- Required: true
- Default:
控制组件是否能够缩放
##### w
- Type: Numberfalse
- Required: 200
- Default:
拖动元素的初始化宽度
`jsx`
##### h
- Type: Numberfalse
- Required: 200
- Default:
拖动元素的初始化高度
`jsx`
##### minw
- Type: Numberfalse
- Required: 50
- Default:
拖动元素的最小宽度
`jsx`
##### minh
- Type: Numberfalse
- Required: 50
- Default:
拖动元素的最小高度
`jsx`
##### x
- Type: Numberfalse
- Required: 0
- Default:
拖动元素初始left值
`jsx`
##### y
- Type: Numberfalse
- Required: 0
- Default:
拖动元素初始top值
`jsx`
##### z
- Type: String | Numberfalse
- Required: auto
- Default:
拖动元素的zIndex值
`jsx`
##### handles
- Type: Arrayfalse
- Required: ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml']
- Default:
控制元素可以拖动的方向
- tl - 左上角tm
- - 上边的中部tr
- - 右上角mr
- - 右边的中部br
- - 右下角bm
- - 下边的中部bl
- - 左下角ml
- - 左边的中部
`jsx`
##### axis
- Type: Stringfalse
- Required: both
- Default:
控制拖动元素的拖动的方向
`jsx`
##### grid
- Type: Arrayfalse
- Required: [1,1]
- Default:
控制拖动元素在x和y轴的每次移动的距离
`jsx`
##### parent
- Type: Booleanfalse
- Required: false
- Default:
控制拖动元素是否只能在父节点中移动和缩放
`jsx`
##### maximize
- Type: Booleanfalse
- Required: false
- Default:
设置为true,则双击拖动元素,充满父元素
`jsx`
##### activated
- Type: Functionfalse
- Required: 无
- Parameters:
当拖动元素被点击的时候调用
`jsx
>
`
##### deactivated
- Type: Functionfalse
- Required: 无
- Parameters:
点击拖动元素之外的区域,拖动元素失去焦点的时候调用
`jsx
>
`
##### resizing
- Type: Functionfalse
- Required: left
- Parameters:
- 拖动元素的left值top
- 拖动元素的top值width
- 拖动元素的宽度height
- 拖动元素的高度
当拖动元素被缩放的时候被调用
`jsxleft: ${left}, top: ${top}, width: ${width}, height: ${height})}}>
`
##### resizestop
- Type: Functionfalse
- Required: left
- Parameters:
- 拖动元素的left值top
- 拖动元素的top值width
- 拖动元素的宽度height
- 拖动元素的高度
当拖动元素缩放停止的时候被调用
`jsxleft: ${left}, top: ${top}, width: ${width}, height: ${height})}}>
`
##### dragging
- Type: Functionfalse
- Required: left
- Parameters:
- 拖动元素的left值top
- 拖动元素的top值
当拖动元素被拖动的时候调用
`jsxleft: ${left}, top: ${top})}}>
`
##### dragstop
- Type: Functionfalse
- Required: left
- Parameters:
- 拖动元素的left值top
- 拖动元素的top值
当拖动元素拖动停止的时候调用
`jsxleft: ${left}, top: ${top})}}>
``