import {useEffect, useRef } from "react";
function useDrop() {
let refone = useRef(null)
let X, Y, isMove = false,left,top
//基于鼠标事件实现拖拽
useEffect(() => {
const dom = refone.current
dom.onmousedown = function (e) {
isMove = true
X = e.clientX - dom.offsetLeft;
Y = e.clientY - dom.offsetTop;
}
dom.onmousemove = function (e) {
if (isMove) {
left = e.clientX - X
top = e.clientY - Y
dom.style.top = top + "px"
dom.style.left = left + "px"
}
}
dom.onmouseup = function (e) {
isMove = false
}
}, [])
return refone
}