安装依赖
npm install react-draggable
Demo:
import React from 'react';
import ReactDOM from 'react-dom';
import Draggable from 'react-draggable';
class App extends React.Component {
eventLogger = (e: MouseEvent, data: Object) => {
console.log('Event: ', e);
console.log('Data: ', data);
};
render() {
return (
<Draggable
axis="x"
handle=".handle"
defaultPosition={{x: 0, y: 0}}
position={null}
grid={[25, 25]}
scale={1}
onStart={this.handleStart}
onDrag={this.handleDrag}
onStop={this.handleStop}>
<button>
按钮
</div>
</Draggable>
);
}
}
ReactDOM.render(<App/>, document.body);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…