代码
export function useDragMouse(dom, container) { let containerX = 0; let containerY = 0; let startX = 0; let startY = 0; function dragPage(e) { container.value.style.left = e.pageX - startX + containerX + "px"; container.value.style.top = e.pageY - startY + containerY + "px"; } dom.value.addEventListener("mousedown", (event) => { container.value.style.opacity = 0.8; startX = event.pageX; startY = event.pageY; containerX = container.value.offsetLeft; containerY = container.value.offsetTop; window.addEventListener("mousemove", dragPage); }); window.addEventListener("mouseup", () => { if (!container.value) { window.removeEventListener("mousemove", dragPage); return; } container.value.style.opacity = 1; window.removeEventListener("mousemove", dragPage); }); }
标签:style,container,函数,dragPage,value,window,let,Vue3,拖拽 From: https://www.cnblogs.com/xiaoqiyaozou/p/18061604