Recommended way of making React component/div draggable

后端 未结 9 702
耶瑟儿~
耶瑟儿~ 2020-11-28 18:13

I want to make a draggable (that is, repositionable by mouse) React component, which seems to necessarily involve global state and scattered event handlers. I can do it the

9条回答
  •  悲哀的现实
    2020-11-28 18:34

    react-draggable is also easy to use. Github:

    https://github.com/mzabriskie/react-draggable

    import React, {Component} from 'react';
    import ReactDOM from 'react-dom';
    import Draggable from 'react-draggable';
    
    var App = React.createClass({
        render() {
            return (
                

    Testing Draggable Windows!

    Drag Here
    You must click my handle to drag me
    ); } }); ReactDOM.render( , document.getElementById('content') );

    And my index.html:

    
        
            Testing Draggable Windows
            
        
        
            

    You need their styles, which is short, or you don't get quite the expected behavior. I like the behavior more than some of the other possible choices, but there's also something called react-resizable-and-movable. I'm trying to get resize working with draggable, but no joy so far.

提交回复
热议问题