You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
constnodeElement=document.getElementById(`N-${node.id}`);if(nodeElement){constcanvasElement=document.getElementById("G-my-canvas");if(canvasElement){constnodeRect=nodeElement.getBoundingClientRect();constcanvasRect=canvasElement.getBoundingClientRect();// Calculate the offset to center the nodeconstoffsetX=nodeRect.left-canvasRect.left-canvasRect.width/2+nodeRect.width/2;constoffsetY=nodeRect.top-canvasRect.top-canvasRect.height/2+nodeRect.height/2;// Adjust the canvas viewcanvasElement.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?
The text was updated successfully, but these errors were encountered:
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:
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?
The text was updated successfully, but these errors were encountered: