Skip to content

Commit

Permalink
perf(theme): improve scroll behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Oct 4, 2024
1 parent cd533d6 commit b515175
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 6 additions & 4 deletions theme/src/client/composables/scroll-behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { inBrowser } from '../utils/index.js'
import { useScrollPromise } from './scroll-promise.js'

export function enhanceScrollBehavior(router: Router) {
// handle scrollBehavior with transition
const scrollBehavior = router.options.scrollBehavior!
router.options.scrollBehavior = async (...args) => {
router.options.scrollBehavior = async (to, from, savedPosition) => {
await useScrollPromise().wait()
return scrollBehavior(...args)
if (savedPosition)
return savedPosition
if (to.hash)
return { el: to.hash, top: 64 }
return { top: 0 }
}

router.beforeEach(() => {
Expand Down
2 changes: 0 additions & 2 deletions theme/src/node/plugins/getPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ export function getPlugins({
activeHeaderLinksPlugin({
headerLinkSelector: 'a.outline-link',
headerAnchorSelector: '.header-anchor',
delay: 200,
offset: 5,
}),
markdownHintPlugin({ hint: true, alert: true, injectStyles: false }),

Expand Down

0 comments on commit b515175

Please sign in to comment.