-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aDragModalHook:useDragModal #5501
Comments
`/**
I should have implemented it, but his closing animation is less than perfect |
is you request like #5554 ? |
yes But I've already done that. But I hope the officials will support it |
我目前的做法,把这个方法在main.js里面执行一下,所有的modal都可以拖动,需要禁止的地方加drag-disabled类名 |
优化鼠标移出标题后窗口不跟随问题: export const useDragModal = (draggableEl: HTMLElement, childrenSelectors = '.n-card-header') => {
const targetEl = draggableEl.querySelector(childrenSelectors) as HTMLElement;
if (!targetEl) {
return;
}
targetEl.style.cursor = 'move';
targetEl.style.userSelect = 'none';
mousedown(targetEl as HTMLElement, draggableEl);
mouseup();
};
const mousedown = (targetEl: HTMLElement, draggableEl: HTMLElement) => {
targetEl.onmousedown = (event: MouseEvent) => {
const viewportWidth = window.innerWidth || document.documentElement.clientWidth;
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
const { width, height, x: minMoveX, y: minMoveY } = draggableEl.getBoundingClientRect();
const maxMoveX = viewportWidth - width - minMoveX;
const maxMoveY = viewportHeight - height - minMoveY;
const { clientX: originX, clientY: originY } = event;
const { left, top } = draggableEl.style;
const styleLeft = left?.replace('px', '') ?? 0;
const styleTop = top.replace('px', '') ?? 0;
document.onmousemove = (e: MouseEvent) => {
const { clientX, clientY } = e;
let moveX = clientX - originX;
let moveY = clientY - originY;
if (moveX > maxMoveX) {
moveX = maxMoveX;
} else if (-moveX > minMoveX) {
moveX = -minMoveX;
}
if (moveY > maxMoveY) {
moveY = maxMoveY;
} else if (-moveY > minMoveY) {
moveY = -minMoveY;
}
draggableEl.style.cssText += `;left:${+styleLeft + moveX}px;top:${+styleTop + moveY}px`;
};
};
};
const mouseup = () => {
document.onmouseup = () => {
document.onmousemove = null;
};
}; |
我特意让鼠标移出就拖动不了的,哈哈哈 |
This function solves the problem (这个功能解决的问题)
Realization of modal drag
Expected API (期望的 API)
useDragModal
The text was updated successfully, but these errors were encountered: