限制拖拽弹窗Y轴范围

This commit is contained in:
dong 2023-12-22 14:44:56 +08:00
parent 5af0362c0e
commit db277254f9
2 changed files with 13 additions and 4 deletions

View File

@ -89,6 +89,7 @@ const offset = reactive({
});
const start = { x: 0, y: 0 };
const startOffset = { x: 0, y: 0 };
onMounted(() => {
window.addEventListener('mousedown', onMouseDown);
@ -99,16 +100,24 @@ onUnmounted(() => {
});
function onMove(e: MouseEvent) {
[offset.x, offset.y] = [e.screenX - start.x, e.screenY - start.y];
let y = e.clientY > startOffset.y ? e.clientY : startOffset.y;
if (y > window.innerHeight - props.titleHeight + startOffset.y) {
y = window.innerHeight - props.titleHeight + startOffset.y;
}
[offset.x, offset.y] = [e.clientX - start.x, y - start.y];
}
function onMouseUp() {
window.removeEventListener('mousemove', onMove);
window.removeEventListener('mouseup', onMouseUp);
startOffset.x = 0;
startOffset.y = 0;
}
function onMouseDown(e: MouseEvent) {
if (headerRef.value?.$el !== e.target) return;
start.x = e.screenX - offset.x;
start.y = e.screenY - offset.y;
startOffset.x = e.offsetX;
startOffset.y = e.offsetY;
start.x = e.clientX - offset.x;
start.y = e.clientY - offset.y;
window.addEventListener('mousemove', onMove);
window.addEventListener('mouseup', onMouseUp);
}

@ -1 +1 @@
Subproject commit 509c8f3f91257e1c489c2bb2435fa66f0fc29cab
Subproject commit c20feed4b6ae3bdd02cb21b4cc5af03c55be869b