
In this tutorial we will check how we can create sticky navigation bar using JavaScript. And the solution for this very easy using vanilla JavaScript.
Lets start with creating some HTML structure. Which have Nav followed by the list item and anchor tags.
Before going through following code check this video which have demo how sticky navigation will work
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<nav> <a href="#" class="logo">Logo</a> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Service</a></li> <li><a href="#">Product</a></li> <li><a href="#">Contact</a></li> </ul> </nav> <div class="background-banner"> <h1>Sticky Navigation Finish</h1> </div> |
Create CSS file style.css and add following css in that.