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,7 +269,11 @@ 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() {
if (
!smooth ||
Math.abs(targetTop - window.scrollY) > window.innerHeight
) {
window.scrollTo(0, targetTop) window.scrollTo(0, targetTop)
} else { } else {
window.scrollTo({ window.scrollTo({
@ -279,6 +283,8 @@ export function scrollTo(el: Element, hash: string, smooth = false) {
}) })
} }
} }
requestAnimationFrame(scrollToTarget)
}
} }
function tryOffsetSelector(selector: string): number { function tryOffsetSelector(selector: string): number {

Loading…
Cancel
Save