@@ -585,8 +585,30 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
585585 const container = document . getElementById ( "global-graph-outer" )
586586 const sidebar = container ?. closest ( ".sidebar" ) as HTMLElement
587587
588+ // 锁定body滚动
589+ const lockBodyScroll = ( ) => {
590+ const scrollY = window . scrollY
591+ document . body . style . position = 'fixed'
592+ document . body . style . top = `-${ scrollY } px`
593+ document . body . style . width = '100%'
594+ document . body . setAttribute ( 'data-scroll-y' , scrollY . toString ( ) )
595+ }
596+
597+ // 解锁body滚动
598+ const unlockBodyScroll = ( ) => {
599+ const scrollY = document . body . getAttribute ( 'data-scroll-y' )
600+ document . body . style . position = ''
601+ document . body . style . top = ''
602+ document . body . style . width = ''
603+ document . body . removeAttribute ( 'data-scroll-y' )
604+ if ( scrollY ) {
605+ window . scrollTo ( 0 , parseInt ( scrollY ) )
606+ }
607+ }
608+
588609 function renderGlobalGraph ( ) {
589610 const slug = getFullSlug ( window )
611+ lockBodyScroll ( )
590612 container ?. classList . add ( "active" )
591613 if ( sidebar ) {
592614 sidebar . style . zIndex = "1"
@@ -597,6 +619,7 @@ document.addEventListener("nav", async (e: CustomEventMap["nav"]) => {
597619 }
598620
599621 function hideGlobalGraph ( ) {
622+ unlockBodyScroll ( )
600623 container ?. classList . remove ( "active" )
601624 if ( sidebar ) {
602625 sidebar . style . zIndex = ""
0 commit comments