a tool for shared writing and social publishing
at update/thread-viewer 17 lines 571 B view raw
1import { scrollIntoViewIfNeeded } from "./scrollIntoViewIfNeeded"; 2 3export function scrollIntoView( 4 elementId: string, 5 scrollContainerId: string = "pages", 6 threshold: number = 0.9, 7) { 8 const element = document.getElementById(elementId); 9 // Use double requestAnimationFrame to ensure the element is fully painted 10 // before attempting to scroll. This fixes smooth scrolling when opening 11 // pages from within other pages. 12 requestAnimationFrame(() => { 13 requestAnimationFrame(() => { 14 scrollIntoViewIfNeeded(element, false, "smooth"); 15 }); 16 }); 17}