fix(client): scroll not working on clicking an anchor in search box (#2527)

pull/2554/head
烽宁 1 year ago committed by GitHub
parent b2a129f49b
commit c30e758585
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)
}
}

Loading…
Cancel
Save