File tree 2 files changed +22
-7
lines changed 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -551,13 +551,6 @@ function playground_text(playground, hidden = true) {
551
551
firstContact = null ;
552
552
}
553
553
} , { passive : true } ) ;
554
-
555
- // Scroll sidebar to current active section
556
- var activeSection = document . getElementById ( "sidebar" ) . querySelector ( ".active" ) ;
557
- if ( activeSection ) {
558
- // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
559
- activeSection . scrollIntoView ( { block : 'center' } ) ;
560
- }
561
554
} ) ( ) ;
562
555
563
556
( function chapterNavigation ( ) {
Original file line number Diff line number Diff line change 110
110
<div id =" sidebar-resize-handle" class =" sidebar-resize-handle" ></div >
111
111
</nav >
112
112
113
+ <!-- Track and set sidebar scroll position -->
114
+ <script >
115
+ var sidebarScrollbox = document .querySelector (' #sidebar .sidebar-scrollbox' );
116
+ sidebarScrollbox .addEventListener (' click' , function (e ) {
117
+ if (e .target .tagName === ' A' ) {
118
+ sessionStorage .setItem (' sidebar-scroll' , sidebarScrollbox .scrollTop );
119
+ }
120
+ }, { passive: true });
121
+ var sidebarScrollTop = sessionStorage .getItem (' sidebar-scroll' );
122
+ sessionStorage .removeItem (' sidebar-scroll' );
123
+ if (sidebarScrollTop) {
124
+ // preserve sidebar scroll position when navigating via links within sidebar
125
+ sidebarScrollbox .scrollTop = sidebarScrollTop;
126
+ } else {
127
+ // scroll sidebar to current active section when navigating via "next/previous chapter" buttons
128
+ var activeSection = document .querySelector (' #sidebar .active' );
129
+ if (activeSection) {
130
+ activeSection .scrollIntoView ({ block: ' center' });
131
+ }
132
+ }
133
+ </script >
134
+
113
135
<div id =" page-wrapper" class =" page-wrapper" >
114
136
115
137
<div class =" page" >
You can’t perform that action at this time.
0 commit comments