fix(nuxt): handle scroll-padding-top: auto in scrollBehavior (#28320)

This commit is contained in:
BoogieBen. 2024-08-07 19:49:24 +08:00 committed by Daniel Roe
parent 274e56488d
commit e64f8c9f3d
No known key found for this signature in database
GPG Key ID: CBC814C393D93268

View File

@ -58,7 +58,7 @@ function _getHashElementScrollMarginTop (selector: string): number {
try {
const elem = document.querySelector(selector)
if (elem) {
return Number.parseFloat(getComputedStyle(elem).scrollMarginTop) + Number.parseFloat(getComputedStyle(document.documentElement).scrollPaddingTop)
return (Number.parseFloat(getComputedStyle(elem).scrollMarginTop) || 0) + (Number.parseFloat(getComputedStyle(document.documentElement).scrollPaddingTop) || 0)
}
} catch {
// ignore any errors parsing scrollMarginTop