refactor: remove requestAnimationFrame and highlight delay from scrollInContainerToElement

This commit is contained in:
neerajadhav 2025-07-08 18:21:14 +05:30
parent d6219339ef
commit 4db33faff7
2 changed files with 11 additions and 16 deletions

View File

@ -130,7 +130,7 @@ async function mouseEnterHandler(
const targetID = `popover-internal-${el.id}` const targetID = `popover-internal-${el.id}`
el.id = targetID el.id = targetID
}) })
const elts = Array.from(html.getElementsByClassName("popover-hint")) const elts = [...html.getElementsByClassName("popover-hint")]
if (elts.length === 0) return if (elts.length === 0) return
elts.forEach((elt) => popoverInner.appendChild(elt)) elts.forEach((elt) => popoverInner.appendChild(elt))

View File

@ -161,8 +161,7 @@ export function scrollInContainerToElement(
highlight: boolean = true, highlight: boolean = true,
behavior: ScrollBehavior = "instant", behavior: ScrollBehavior = "instant",
) { ) {
// Use requestAnimationFrame to ensure content is rendered before scrolling // Scroll immediately, since content should already be rendered in a static site
requestAnimationFrame(() => {
const targetPosition = target.offsetTop - buffer const targetPosition = target.offsetTop - buffer
container.scroll({ container.scroll({
top: Math.max(0, targetPosition), top: Math.max(0, targetPosition),
@ -171,10 +170,6 @@ export function scrollInContainerToElement(
// Add highlight effect if requested // Add highlight effect if requested
if (highlight) { if (highlight) {
// Small delay to ensure scroll completes before highlighting
setTimeout(() => {
highlightElement(target) highlightElement(target)
}, 50)
} }
})
} }