From e64f8c9f3de3cfc82cdff85f31a1a1489a184a5f Mon Sep 17 00:00:00 2001 From: "BoogieBen." Date: Wed, 7 Aug 2024 19:49:24 +0800 Subject: [PATCH] fix(nuxt): handle `scroll-padding-top: auto` in scrollBehavior (#28320) --- packages/nuxt/src/pages/runtime/router.options.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nuxt/src/pages/runtime/router.options.ts b/packages/nuxt/src/pages/runtime/router.options.ts index b57e56a958..a415cc52f3 100644 --- a/packages/nuxt/src/pages/runtime/router.options.ts +++ b/packages/nuxt/src/pages/runtime/router.options.ts @@ -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