关于javascript:Day-18100-reactdraggable-实现组件拖拽功能

1、需要

想实现页面弹窗的拖拽性能,原生手写时,根本逻辑能实现,然而拖拽双击操作时,会有bug,待解决,就想着看看有没有适合的组件,发现还真有~

2、介绍

周下载量300w+

2.1反对有各种拖拽状况的Demo实现
2.1反对有各种拖拽状况的Demo实现;大略十几种;

2.2反对React16.3+

2.3 根本代码
<Draggable>
  <div>I can now be moved around!</div>
</Draggable>

3、Demo样例

// Copyright 2021 zhaoarden
import React from 'react';
import Draggable from 'react-draggable'; // The default
import { Modal,Button } from 'antd';
import "antd/dist/antd.css";
class Dragable extends React.Component {
    constructor(props) {
        super(props);
        this.state={
            visible: false
        }
    }
    componentDidMount(){
    };
    render() {
        const {visible}=this.state
        const clickName=()=>{
            this.setState({visible:true});
            console.log('clickName');
        }
        const handleOk = () => {
            this.setState({visible:false});
        };
        const handleCancel = () => {
            this.setState({visible:false});
        };
        return <div>
            <h1>Learn, {this.props.name}</h1>
            <Button type="primary"  onClick={clickName}>Primary Button</Button>
            <Modal title="Basic Modal" visible={visible} onOk={handleOk} onCancel={handleCancel}>
                <Draggable>
                    <div>I can now be moved around!</div>
                </Draggable>
            </Modal>
        </div>;
    }
}
export default Dragable;

可运行的Demo的GitHub仓库
https://github.com/iguoxing/r…

参考资料

https://www.npmjs.com/package…

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理