How to change your navigation style on scroll

Kevin Powell on YouTubeWatch on YouTube

SaveMark complete

Sign in to save videos and track what you’ve finished.

IntermediateUI13 min

About this video

A front-end tutorial that uses the Intersection Observer API and a small amount of JavaScript to add or remove a class on a fixed navigation bar as the page scrolls. It assumes some familiarity with HTML, CSS and JavaScript.

What you’ll learn

  • Detect when an element leaves the viewport with the Intersection Observer API
  • Toggle a navigation class on scroll using JavaScript
  • Prepare CSS custom properties so the navigation style change stays simple