Skip to content

Commit

Permalink
internal: utilizes translate/transform to synthetically move node aro…
Browse files Browse the repository at this point in the history
…und as opposed to manipulating the top and left positions
  • Loading branch information
sashamilenkovic committed Dec 9, 2024
1 parent b55ee8b commit a68f27a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2078,21 +2078,21 @@ function cancelSynthScroll<T>(state: SynthDragState<T>) {
state.animationFrameIdY = undefined;
}
}

function moveNode<T>(e: PointerEvent, state: SynthDragState<T>) {
const { x, y } = eventCoordinates(e);

state.coordinates.y = y;

state.coordinates.x = x;

const startLeft = state.startLeft ?? 0;

const startTop = state.startTop ?? 0;

state.clonedDraggedNode.style.top = `${y - startTop + window.scrollY}px`;
// Calculate the translation values
const translateX = x - startLeft + window.scrollX;
const translateY = y - startTop + window.scrollY;

state.clonedDraggedNode.style.left = `${x - startLeft + window.scrollX}px`;
// Apply the transform using translate
state.clonedDraggedNode.style.transform = `translate(${translateX}px, ${translateY}px)`;

if (e.cancelable) e.preventDefault();

Expand Down

0 comments on commit a68f27a

Please sign in to comment.