0

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.

4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.