tl;dr: Use position: sticky; to create parallax effects. Avoid any JavaScript as much as possible and use native CSS to handle the logic because it’s much more performant.

nav {
  position: sticky;
  top: 100px;
}