mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-17 06:01:34 +00:00
fix(vue-app): respect scroll-margin-top
when navigating with hash (#9187)
This commit is contained in:
parent
877ebcd3a0
commit
00aeff62e7
@ -66,9 +66,15 @@ export default function (to, from, savedPosition) {
|
|||||||
hash = '#' + window.CSS.escape(hash.substr(1))
|
hash = '#' + window.CSS.escape(hash.substr(1))
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (document.querySelector(hash)) {
|
const el = document.querySelector(hash)
|
||||||
|
if (el) {
|
||||||
// scroll to anchor by returning the selector
|
// scroll to anchor by returning the selector
|
||||||
position = { selector: hash }
|
position = { selector: hash }
|
||||||
|
// Respect any scroll-margin-top set in CSS when scrolling to anchor
|
||||||
|
const y = Number(getComputedStyle(el)['scroll-margin-top']?.replace('px', ''))
|
||||||
|
if (y) {
|
||||||
|
position.offset = { y }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
<%= isTest ? '// eslint-disable-next-line no-console' : '' %>
|
<%= isTest ? '// eslint-disable-next-line no-console' : '' %>
|
||||||
|
Loading…
Reference in New Issue
Block a user