-
-
Notifications
You must be signed in to change notification settings - Fork 175
Open
Description
Hi,
I'm trying to scroll a node into view when a reference of it is clicked from somewhere. My logic was was to get the bounding rect of the svelvet canvas and the node rect, calculate the offset, and scroll that into view:
const nodeElement = document.getElementById(`N-${node.id}`);
if (nodeElement) {
const canvasElement = document.getElementById("G-my-canvas");
if (canvasElement) {
const nodeRect = nodeElement.getBoundingClientRect();
const canvasRect = canvasElement.getBoundingClientRect();
// Calculate the offset to center the node
const offsetX =
nodeRect.left -
canvasRect.left -
canvasRect.width / 2 +
nodeRect.width / 2;
const offsetY =
nodeRect.top -
canvasRect.top -
canvasRect.height / 2 +
nodeRect.height / 2;
// Adjust the canvas view
canvasElement.scrollBy({
top: offsetY,
left: offsetX,
behavior: "smooth",
});
}
}
However, this shifts/translates the canvas as a whole (as opposed to shifting the content within the canvas).
Is there a way to scroll/focus upon a node itself?
Metadata
Metadata
Assignees
Labels
No labels