English | 中文说明
Using the free drag and drop component of Transform, the drag process does not affect the page layout
- Remove
ReactDOM.findDOMNode
, change to ref reference to get the dom. if children is a function component, you need to wrap it withReact.forwardRef
. - Change the parameters of
onStart
,onMove
,onEnd
callbacks property tofixed
resetOnEnd
property to indicate whether to restore the position after the drag endproperty is deprecatedchildProps
property is deprecatedchildProps
- 8.1.0
andshowLayer
deprecated.layerStyle
- Using
tranform
to realize element drag and drop movement, high performance, smooth - You can set the drag bounds
bounds
to limit the scope of the drag by setting the parent element, Full-screen drag is the default - Other properties of the wrapped
props. children
(properties that are not drag related) are not affected byreact-free-draggable
. It's still the same as not being wrapped - When set to
position: absolute
, you can set thex
andy
attributes inside thebounds
element to control the position of the element
- Provide only drag event callbacks and parameters for dragging
- The
eventBounds
property can limit the extent of the event object's activity
- children can not be inline elements, because transform does not work on inline elements!
props.children
is restricted to a single closing tag!x
andy
attributes are referenced to thebounds
element.
npm install --save react-free-draggable
# or
yarn add react-free-draggable
import Draggable from 'react-free-draggable';
<div className="boxs" style={{ display: 'inline-block', width: '500px', background: "red" }}>
<Draggable
bounds=".boxs"
scale={1}
>
<div style={{ display: "inline-block" }}>
<div className="handle" style={{ display: "inline-block", width: "80px",background: "blue", cursor: "pointer", height: "100%" }} onClick={this.clickToast}>
The Dragging
</div>
</div>
</Draggable>
</div>
name | type | defaultValue | description |
---|---|---|---|
handle | string / HTMLElement |
- | Drag the class selector or element for the element |
filter | string / HTMLElement |
- | A selector or element that does not allow drag and drop |
enableUserSelectHack | boolean |
- | Allows you to add selected styles |
grid | [number, number] |
- | Set X, Y direction amplitude, how much to move the target |
disabled | boolean |
- | disabled drag |
allowAnyClick | boolean |
- | Indicates that drag is allowed without a left mouse click |
onStart | function |
- | the start event |
onMove | function |
- | the dragging event |
onEnd | function |
- | the end event |
scale | number |
1 | Drag sensitivity |
x | number |
- | The position of the x-axis when the element is position: absolute . |
y | number |
- | The position of the y-axis when the element is position: absolute . |
direction | ['vertical','horizontal'] |
- | the direction of drag and drop |
positionOffset | {x: number, y: number} |
- | Transform position increment |
bounds | string / HTMLElement / {left: number, right: number, top: number, bottom: number, element: string / HTMLElement } |
- | The range within the element, if it is element, the position is range in element, but if it is object, it is the range of the element element |
resetOnEnd | boolean |
- | Restore position when drag end |