参考文章:https://segmentfault.com/a/1190000021880340
原文章用的是ts语法,没去了解过ts,这里直接改成了js写法,文件格式为.jsx,在其基础上完善了一下只能在页面视口范围内移动对话框
用法和普通的Modal一样
代码:
import React, {
Component } from 'react';
import AntdModal from 'antd/lib/modal';
import 'antd/es/modal/style/index.css';
export default class AntDraggableModal extends Component {
constructor(props) {
super(props);
this.simpleClass = "";
this.header;
this.contain;
this.modalContent;
this.mouseDownX = 0;
this.mouseDownY = 0;
this.deltaX = 0;
this.deltaY = 0;
this.translate_x = 0;
this.translate_Y = 0;
this.simpleClass = Math.random()
.toString(36)
.substring(2);
}
handleMove = (event) => {
const deltaX = event.pageX