In this Tutorial We will explain to a fixed menu on the scroll with jQuery, What we are going to do is to have the navigation fixed when user scrolling the page and back to its original position when scrolling back to the top.
In this guide, We only use few lines of JS functions to make the fixed menu working.
Ok, let’s start.
Navigation HTML Code
This contains our menu HTML element of the Menu bar, this is just a simple HTML UL tag to make our menus but if you already have one then use that instead.
Note: If you’re going to use your old menus make sure to replace the class in JS code.
Navigation CSS Code
To make our menu list horizontally we need to add CSS code.
We set the z-index very high since we don’t want any other absolute element to be on top of our navigation and add within percent to the center menu while scrolling.
This small JS code contains the main functions of our fixed scroll menu.
So, If we scroll our page, it will add a class
#navigation For instance when page scroll, the css
#navigation.sticky will run and make it fixed. And when we scroll up it will remove the
That’s it guys. Hope it was helpful for you.