File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
apps/svelte.dev/src/routes/docs/[...path] Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 1010 afterNavigate (() => {
1111 current = location .hash .slice (1 );
1212 headings = content .querySelectorAll (' h2' );
13+ update (); // Ensure active link is set correctly on navigation
1314 });
1415
16+ // Update function to activate the correct section link
1517 function update() {
16- // a section is 'active' when it crosses the threshold
1718 const threshold = (innerHeight * 1 ) / 3 ;
19+ let found = false ;
1820
19- for (let i = 0 ; i < headings .length ; i += 1 ) {
21+ for (let i = 0 ; i < headings .length ; i ++ ) {
2022 const heading = headings [i ];
2123 const next = headings [i + 1 ];
2224
25+ // If the current heading is above the threshold and the next heading is below it
2326 if (
24- next &&
2527 heading .getBoundingClientRect ().top < threshold &&
26- next .getBoundingClientRect ().top > threshold
28+ ( ! next || next .getBoundingClientRect ().top > threshold )
2729 ) {
2830 current = heading .id ;
31+ found = true ;
2932 break ;
3033 }
3134 }
35+
36+ // Handle case when scrolled to the top of the page
37+ if (! found && scrollY === 0 ) {
38+ current = ' ' ;
39+ }
3240 }
3341 </script >
3442
You can’t perform that action at this time.
0 commit comments