no more box offset
All checks were successful
Deploy to Cloudflare Pages / deploy (push) Successful in 29s

This commit is contained in:
christian 2024-11-03 12:57:42 +01:00
parent df3a23a74a
commit dc5247c4db

View File

@ -34,13 +34,12 @@ const DraggableBox = ({
const parent = dragRef.current.parentElement;
const parentRect = parent.getBoundingClientRect();
const boxRect = dragRef.current.getBoundingClientRect();
const relativeX = e.clientX - parentRect.left - dragOffset.x;
const relativeY = e.clientY - parentRect.top - dragOffset.y;
const maxX = parentRect.width - boxRect.width;
const maxY = parentRect.height - boxRect.height;
const maxX = parentRect.width;
const maxY = parentRect.height;
let newX = (Math.max(0, Math.min(relativeX, maxX)));
let newY = (Math.max(0, Math.min(relativeY, maxY)));