Skip to content

Commit 6497d6a

Browse files
committed
fix: underlines the wrong section title
Signed-off-by: Sanajit Jana <[email protected]>
1 parent 5c79e0a commit 6497d6a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

apps/svelte.dev/src/routes/docs/[topic]/[...path]/OnThisPage.svelte

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@
1010
afterNavigate(() => {
1111
current = location.hash.slice(1);
1212
headings = content.querySelectorAll('h2');
13-
update(); // Ensure active link is set correctly on navigation
13+
setTimeout(() => update(), 0); // Delay to allow layout to settle
1414
});
1515
1616
// Update function to activate the correct section link
1717
function update() {
1818
const threshold = (innerHeight * 1) / 3;
19+
20+
// If scrolled less than threshold, activate the page title
21+
if (scrollY < threshold) {
22+
current = '';
23+
return;
24+
}
25+
1926
let found = false;
2027
2128
for (let i = 0; i < headings.length; i++) {
@@ -33,10 +40,7 @@
3340
}
3441
}
3542
36-
// Handle case when scrolled to the top of the page
37-
if (!found && scrollY === 0) {
38-
current = '';
39-
}
43+
// If no heading found, keep current as is
4044
}
4145
</script>
4246

0 commit comments

Comments
 (0)