Skip to content

Add offset option to scrollspy initialization#3354

Merged
alshedivat merged 2 commits intoalshedivat:mainfrom
wiestju:patch-1
Nov 7, 2025
Merged

Add offset option to scrollspy initialization#3354
alshedivat merged 2 commits intoalshedivat:mainfrom
wiestju:patch-1

Conversation

@wiestju
Copy link
Copy Markdown
Contributor

@wiestju wiestju commented Nov 5, 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

  • ToC correctly highlights the current section immediately after clicking
  • Headings remain visible (not hidden under header)
  • Smooth scrolling works as expected

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.
@netlify
Copy link
Copy Markdown

netlify Bot commented Nov 5, 2025

Deploy Preview for relaxed-lollipop-b6bc17 ready!

Name Link
🔨 Latest commit 0c8b799
🔍 Latest deploy log https://app.netlify.com/projects/relaxed-lollipop-b6bc17/deploys/690e50d86056e60008179e9f
😎 Deploy Preview https://deploy-preview-3354--relaxed-lollipop-b6bc17.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@alshedivat alshedivat merged commit 729f136 into alshedivat:main Nov 7, 2025
10 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants