Add offset option to scrollspy initialization (#3354)

## Fix ToC Scroll-Spy Highlighting Issue

### Problem
When clicking on a ToC link in the sidebar, the page scrolls to the
correct section, but the ToC highlights the *previous* section instead
of the current one. The correct section only gets highlighted after
scrolling down a few pixels.

### Root Cause
The `scrollspy` in `assets/js/common.js` was initialized without an
offset parameter, so it didn't account for the fixed navigation header
height (~56px).

### Solution
Added `offset: 100` parameter to the scrollspy initialization to
properly detect when a section becomes visible, accounting for the
header and some buffer space.

### Changes
- Modified `assets/js/common.js`: Added offset parameter to scrollspy
configuration

### Testing
- [x] ToC correctly highlights the current section immediately after
clicking
- [x] Headings remain visible (not hidden under header)
- [x] Smooth scrolling works as expected

---------

Co-authored-by: Maruan <alshedivat@users.noreply.github.com>
This commit is contained in:
Julian Wiest 2025-11-07 21:15:08 +01:00 committed by GitHub
parent 0d07f7ca51
commit 729f136fb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -28,6 +28,7 @@ $(document).ready(function () {
Toc.init($myNav); Toc.init($myNav);
$("body").scrollspy({ $("body").scrollspy({
target: navSelector, target: navSelector,
offset: 100,
}); });
} }