Skip to content

Commit

Permalink
fix(client): scroll not working on clicking an anchor in search box (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zonemeen authored Jun 24, 2023
1 parent b2a129f commit c30e758
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/client/app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,21 @@ export function scrollTo(el: Element, hash: string, smooth = false) {
offset +
targetPadding
// only smooth scroll if distance is smaller than screen height.
if (!smooth || Math.abs(targetTop - window.scrollY) > window.innerHeight) {
window.scrollTo(0, targetTop)
} else {
window.scrollTo({
left: 0,
top: targetTop,
behavior: 'smooth'
})
function scrollToTarget() {
if (
!smooth ||
Math.abs(targetTop - window.scrollY) > window.innerHeight
) {
window.scrollTo(0, targetTop)
} else {
window.scrollTo({
left: 0,
top: targetTop,
behavior: 'smooth'
})
}
}
requestAnimationFrame(scrollToTarget)
}
}

Expand Down

0 comments on commit c30e758

Please sign in to comment.