Skip to content

Commit

Permalink
fix: include fixed header height for scroll to
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyxguo committed Aug 22, 2023
1 parent d1ca38c commit fb289cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/hooks/useJumpToEle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export default function useJumpToEle() {
return offsetTop
}

// -31 for top padding of the app container
// -81 for fixed header
const jumpToEle = (id: string) => {
element.value = document.getElementById(id)
if (element.value) {
elementOffsetTop.value =
element.value && element.value instanceof HTMLElement
? getOffsetTop(element.value) - 30
? getOffsetTop(element.value) - 30 - 81
: 0
}
window.scrollTo({
Expand Down
2 changes: 1 addition & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const router = createRouter({
return new Promise(resolve => {
if (to.hash) {
setTimeout(() => {
resolve({ el: to.hash, behavior: 'smooth' })
resolve({ el: to.hash, behavior: 'smooth', top: 81 })
}, 1500)
} else if (savedPosition) {
resolve(savedPosition)
Expand Down

0 comments on commit fb289cc

Please sign in to comment.