File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 204204 const sidebar = document . getElementById ( 'sidebar' ) ;
205205 const footer = document . querySelector ( 'footer' ) ;
206206
207+ // Scroll sidebar to show active page on load
208+ const activeLink = sidebar . querySelector ( 'a.active' ) ;
209+ if ( activeLink ) {
210+ // Find the scrollable UL container that contains the active link
211+ const scrollContainer = activeLink . closest ( 'ul.overflow-y-auto' ) ;
212+
213+ if ( scrollContainer ) {
214+ // Get the position of the active link relative to its scrollable container
215+ const linkRect = activeLink . getBoundingClientRect ( ) ;
216+ const containerRect = scrollContainer . getBoundingClientRect ( ) ;
217+
218+ // Calculate how far the link is from the top of the container
219+ const relativeTop = linkRect . top - containerRect . top + scrollContainer . scrollTop ;
220+
221+ // Scroll so the active link appears near the top (with some padding)
222+ const scrollPosition = relativeTop - 20 ; // 20px padding from top
223+
224+ scrollContainer . scrollTop = Math . max ( 0 , scrollPosition ) ;
225+ }
226+ }
227+
207228 window . addEventListener ( 'scroll' , function ( ) {
208229 const scrolledHeight = window . scrollY + window . innerHeight ;
209230 if ( scrolledHeight >= footer . offsetTop ) {
You can’t perform that action at this time.
0 commit comments