Add offset option to scrollspy initialization#3354
Merged
alshedivat merged 2 commits intoalshedivat:mainfrom Nov 7, 2025
wiestju:patch-1
Merged
Add offset option to scrollspy initialization#3354alshedivat merged 2 commits intoalshedivat:mainfrom wiestju:patch-1
alshedivat merged 2 commits intoalshedivat:mainfrom
wiestju:patch-1
Conversation
Fix ToC scroll-spy offset for accurate section highlighting The table of contents was highlighting the wrong section when clicking on links - always showing the previous section instead of the current one. This was caused by the missing offset parameter in the scrollspy initialization, which didn't account for the fixed header height. Added offset: 100 to properly detect section visibility and highlight the correct ToC item. Fixes sidebar ToC navigation accuracy.
✅ Deploy Preview for relaxed-lollipop-b6bc17 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Tzxtoiny
pushed a commit
to Tzxtoiny/Tzxtoiny.github.io
that referenced
this pull request
Nov 20, 2025
## 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>
ruiwen0615
pushed a commit
to ruiwen0615/ruiwen0615.github.io
that referenced
this pull request
Jan 12, 2026
## 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>
vltanh
pushed a commit
to vltanh/vltanh.github.io
that referenced
this pull request
Apr 28, 2026
## 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>
Patra2020
pushed a commit
to Patra2020/Patra2020.github.io
that referenced
this pull request
May 3, 2026
## 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
scrollspyinassets/js/common.jswas initialized without an offset parameter, so it didn't account for the fixed navigation header height (~56px).Solution
Added
offset: 100parameter to the scrollspy initialization to properly detect when a section becomes visible, accounting for the header and some buffer space.Changes
assets/js/common.js: Added offset parameter to scrollspy configurationTesting