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

pull/2554/head
烽宁 2 years 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 + offset +
targetPadding targetPadding
// only smooth scroll if distance is smaller than screen height. // only smooth scroll if distance is smaller than screen height.
if (!smooth || Math.abs(targetTop - window.scrollY) > window.innerHeight) { function scrollToTarget() {
window.scrollTo(0, targetTop) if (
} else { !smooth ||
window.scrollTo({ Math.abs(targetTop - window.scrollY) > window.innerHeight
left: 0, ) {
top: targetTop, window.scrollTo(0, targetTop)
behavior: 'smooth' } else {
}) window.scrollTo({
left: 0,
top: targetTop,
behavior: 'smooth'
})
}
} }
requestAnimationFrame(scrollToTarget)
} }
} }

Loading…
Cancel
Save