Monday 1 September 2014

How to create Fixed Menu When Scrolling Page with CSS and jQuery

HTML

This contains our menu HTML element, 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.


CSS

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 with in percent to center menu while scrolling.

Javascript

This small JS code contains the main functions of our fixed scroll menu.


So, if we are on the top less than 136 height in pixel the menu is in the original position and add f-nav CSS class when greater than 136px height or add f-nav CSS class on scroll, where the top page greater than 136px height.
That’s it, its easy right? Enjoy!

No comments:

Post a Comment