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