Skip to content

Make navigation always sticky, remove headroom.js#1356

Open
slightlyoffbeat wants to merge 1 commit into
mainfrom
nav-sticky
Open

Make navigation always sticky, remove headroom.js#1356
slightlyoffbeat wants to merge 1 commit into
mainfrom
nav-sticky

Conversation

@slightlyoffbeat
Copy link
Copy Markdown
Contributor

The nav was using headroom.js to hide on scroll-down and reappear on scroll-up. We're switching to a permanently-pinned nav

The "scrolled past top" state (used for a subtle drop-shadow under the nav) is now detected with a 1px sentinel element + IntersectionObserver instead of headroom's scroll listener (same visual, no library).

Also:

  • Add scroll-padding-block-start so in-page anchor links account for the sticky nav.
  • Disable the shadow transition under prefers-reduced-motion.
  • Remove now-dead body:has(.fl-landing-get) .headroom-unpinned override.
  • Drop headroom.js dependency.

Saves about 5kb in bundle

The nav was using headroom.js to hide on scroll-down and reappear on scroll-up. We're switching to a permanently-pinned nav

The "scrolled past top" state (used for a subtle drop-shadow under
the nav) is now detected with a 1px sentinel element + IntersectionObserver instead of headroom's scroll listener (same visual, no library).

Also:
- Add `scroll-padding-block-start` so in-page anchor links account
  for the sticky nav.
- Disable the shadow transition under `prefers-reduced-motion`.
- Remove now-dead `body:has(.fl-landing-get) .headroom-unpinned` override.
- Drop headroom.js dependency.
Copy link
Copy Markdown
Contributor

@janriokrause janriokrause left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+ Looks good to me!

Nice touch adding scroll-padding-* to avoid anchor jump under the sticky header, and honoring prefers-reduced-motion

If we want to support very old browsers, we could consider a lightweight fallback like always add is-scrolled or use a simple scroll listener when IntersectionObserver is unavailable. But I think it's fine.

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