I'm trying to fix a div but only when I'm scrolling down.
I have this template :
<div>
<div class="header">Title</div> // A header that will not be fixed
<div class="sticky">Navbar</div> // A div that will be fixed when scrolling down
<div class="content">...</div> // The rest of the page
</div>
So the idea is that, when opening the page I have the 3 div displayed in the same order as the code (so header then sticky then content). And when I scroll down, the sticky is fixed while I navigate the content.
I've tried to put a listener on scroll but I don't see how I can put a {position: fixed} only when scrolled and nothing when I return to initial position.
position: sticky? Most modern browsers support it already.