2014-02-28, 20:56
Tutorial: Fixed menu on scroll |
This is a tutorial where you gonna learn on how to change the menu state, to fixed on top when the user scroll the page..
--> Tutorials, tips and tricks <--
Fixed menu on scroll
Fixed menu on scroll
1º - Javascript
You just need to configure it
- Code:
[panda=js]$(function($){
var
//ID of the element you want to affect
nav = jQuery('#primary_nav'),
//How much the user need to scroll the page to the element get fixed
scrollSize = 120,
//Nothing important..
Jthis = jQuery(this);
jQuery(window).scroll(function () {
if ( Jthis.scrollTop() > scrollSize ) {
nav.css({
//CSS styles - To add one more, just do like this 'property':'value' and a comma after, just if aren't the last style attribute
'position':'fixed',
'top':'0',
'left':'0',
'right':'0',
'padding':'4px 0',
'z-index':'9999'
});
} else {nav.attr('style','');}
});
})(jQuery);
2º - Configurations
On our Javascript code, change the "ID of the element you want to affect", to the corresponding element ID.
Change "How much the user need to scroll the page to the element get fixed" to a value you want.
And if you want just put new CSS styles on it..
It's fast and easy! The code is commented to be more easy to configure!
© Wagner
If you have any questions related to this topic create a topic with the following title: Fixed menu on scroll |