File tree Expand file tree Collapse file tree 1 file changed +21
-11
lines changed
Expand file tree Collapse file tree 1 file changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import './style/global.css'
1414import '@nolebase/vitepress-plugin-enhanced-readabilities/client/style.css'
1515import VersionSwitcher from "./components/VersionSwitcher.vue" ;
1616
17+ // noinspection JSUnusedGlobalSymbols
1718export default {
1819 extends : DefaultTheme ,
1920 enhanceApp ( { app} ) {
@@ -34,16 +35,25 @@ export default {
3435 return h ( DefaultTheme . Layout , null , children ) ;
3536 } ,
3637 setup ( ) {
37- const route = useRoute ( )
38- const initZoom = ( ) => {
39- mediumZoom ( '.main img' , { background : 'var(--vp-c-bg)' } )
40- }
41- onMounted ( ( ) => {
38+ const route = useRoute ( ) ;
39+ onMounted ( async ( ) => {
4240 initZoom ( )
43- } )
44- watch (
45- ( ) => route . path ,
46- ( ) => nextTick ( ( ) => initZoom ( ) )
47- )
41+ await nextTick ( ( ) => scrollToActiveSidebarItem ( ) )
42+ } ) ;
43+ watch ( ( ) => route . path , ( ) => nextTick ( ( ) => {
44+ scrollToActiveSidebarItem ( )
45+ initZoom ( )
46+ } ) ) ;
47+ }
48+ } satisfies Theme
49+
50+ function initZoom ( ) {
51+ mediumZoom ( '.main img' , { background : 'var(--vp-c-bg)' } )
52+ }
53+
54+ function scrollToActiveSidebarItem ( ) {
55+ const activeLink = document . querySelector ( '#VPSidebarNav div.is-link.is-active.has-active' )
56+ if ( activeLink ) {
57+ activeLink . scrollIntoView ( { behavior : 'smooth' , block : 'center' } )
4858 }
49- } satisfies Theme
59+ }
You can’t perform that action at this time.
0 commit comments