Skip to content

Commit c30e758

Browse files
authored
fix(client): scroll not working on clicking an anchor in search box (#2527)
1 parent b2a129f commit c30e758

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/client/app/router.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,21 @@ export function scrollTo(el: Element, hash: string, smooth = false) {
269269
offset +
270270
targetPadding
271271
// only smooth scroll if distance is smaller than screen height.
272-
if (!smooth || Math.abs(targetTop - window.scrollY) > window.innerHeight) {
273-
window.scrollTo(0, targetTop)
274-
} else {
275-
window.scrollTo({
276-
left: 0,
277-
top: targetTop,
278-
behavior: 'smooth'
279-
})
272+
function scrollToTarget() {
273+
if (
274+
!smooth ||
275+
Math.abs(targetTop - window.scrollY) > window.innerHeight
276+
) {
277+
window.scrollTo(0, targetTop)
278+
} else {
279+
window.scrollTo({
280+
left: 0,
281+
top: targetTop,
282+
behavior: 'smooth'
283+
})
284+
}
280285
}
286+
requestAnimationFrame(scrollToTarget)
281287
}
282288
}
283289

0 commit comments

Comments
 (0)