Many websites use a “sticky” feature in their main navigation menu. The menu scrolls with the page, then sticks to the top once it reaches the top of the viewport. There are lots of jQuery plugins we can use to display a sticky navigation, but in this short video, we’ll learn how to build our own with a few lines of code!
NOTE: I made a few changes to the JavaScript in the final CodePen Demo. Notice the more efficient use of variables in the scroll
function.
If you’d like to learn more about HTML and CSS, check out our guided path of Web Design courses now available at Treehouse!
Guil, you are the man!! Thank you so much for your easy to understand lesson. I will use it immediately for a project. God bless you.
Nice tut, thanks !
Man thats amazing , I was searching for such thing for weeks and now finally i found somthing worth. I used it on my blog and its running flawless .Thanks and keep the great work up.
Thanks for this video. It is so easy and simple to apply.
Also i have a question.
Did you have any document working on sticky menu but using native javascript?
I m having problems with SEO when using jquery (pagespeed insights indicates jquery lags my sites) and when i use basic javascript for easy animations i have no problems so I ll be grateful if you lead me to javascript only for sticky menu. Thank you very much again.
Thanks for sharing your info. I truly appreciate your efforts and I will be waiting for your next write ups thanks once again.|
I am getting more and more requests for a sticky navigation, thanks for the quick tips. Its really trending right now.
very good tut indeed
Awesome tutorial Guil! Thanks for taking time out to show this.
thank you for sharing this post
im looking for this shot….thanks man
Thanks for a great tutorial Guil. Really good stuff.
Was wondering your thoughts on instead of using the body tag to reveal header ( via body {padding-top: 250px} ), what if a container were used to to wrap around the .header and .main to achieve same goal? Are wrapper classes not recommended in this case? thanks!
i.e
Awesome! I always look forward to your posts because I usually use them immediately for a client project. Thanks!
Nice! Thanks for reading. 🙂
Great!