Change style header/nav with Intersection Observer (IO)
Instead of listening to scroll event you should have a look at Intersection Observer (IO). This was designed to solve problems like yours. And it is much more performant than listening to scroll events and then calculating the position yourself. First, here is a codepen which shows a solution for your problem. I am not … Read more