Skip to content

Commit 9b35dfc

Browse files
committed
fix: avoid scroll behavior reliance on .nav-bar class
1 parent 3fed6f9 commit 9b35dfc

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/client/app/components/Content.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export const Content = defineComponent({
55
name: 'VitePressContent',
66
setup() {
77
const route = useRoute()
8-
return () => (route.component ? h(route.component) : null)
8+
return () =>
9+
h('div', { style: { position: 'relative' } }, [
10+
route.component ? h(route.component) : null
11+
])
912
}
1013
})

src/client/app/router.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,11 @@ export function useRoute(): Route {
172172
}
173173

174174
function scrollTo(el: HTMLElement, hash: string, smooth = false) {
175-
const nav = document.querySelector('.nav-bar')
176-
const pageOffset = nav ? (nav as HTMLElement).offsetHeight : 0
177175
const target = el.classList.contains('.header-anchor')
178176
? el
179177
: document.querySelector(decodeURIComponent(hash))
180178
if (target) {
181-
const targetTop = (target as HTMLElement).offsetTop - pageOffset - 15
179+
const targetTop = (target as HTMLElement).offsetTop
182180
// only smooth scroll if distance is smaller than screen height.
183181
if (!smooth || Math.abs(targetTop - window.scrollY) > window.innerHeight) {
184182
window.scrollTo(0, targetTop)

src/client/theme-default/components/Page.vue

+1-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ import NextAndPrevLinks from './NextAndPrevLinks.vue'
88
<div class="container">
99
<slot name="top" />
1010

11-
<div class="content">
12-
<Content />
13-
</div>
14-
11+
<Content class="content" />
1512
<PageFooter />
16-
1713
<NextAndPrevLinks />
1814

1915
<slot name="bottom" />

0 commit comments

Comments
 (0)