Fixed Position Top Menu Bar with jQuery and CSS3 - nagging-menu

Fixed Position Top Menu Bar with jQuery and CSS3 - nagging-menu
File Size: 28.8 KB
Views Total:
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

nagging-menu is a jQuery plugin that allows you to create a floating and fixed position top menu bar on your webpage. The floating menu bar is invisible until you scroll down and then it appears. If you're looking for a simple fixed top menu bar without using jQuery, please check out our another article Sticky Top Menu Bar with CSS3.

How to use it:

1. Markup

<div id="menu" class="default">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">CSS</a></li>
<li><a href="#">Design</a></li>
<li><a href="#">Development</a></li>
<li><a href="#">Freebies</a></li>
<li><a href="#">Inspiration</a></li>
<li><a href="#">Resources</a></li>
<li><a href="#">Tutorials</a></li>
<li><a href="#">WordPress</a></li>
</ul>
</div>

2. The Menu CSS

/* Menu */

#menu {
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #426d9c), color-stop(40%, #0f67a1), color-stop(100%, #1384d1));
background: -moz-linear-gradient(top, #426d9c, #0f67a1, #1384d1);
border-radius: 5px;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
line-height: 50px;
text-align: center;
margin: 0 auto;
padding: 0;
}

/* Default Style */

.default {
width: 850px;
height: 50px;
box-shadow: 0 5px 20px #888;
-webkit-box-shadow: 0 5px 20px #888;
-moz-box-shadow: 0 5px 20px #888;
}


/* CSS3 position: fixed */
.fixed {
position: fixed;
top: -5px;
left: 0;
width: 100%;
box-shadow: 0 0 40px #222;
-webkit-box-shadow: 0 0 40px #222;
-moz-box-shadow: 0 0 40px #222;
}

3. Include jQuery Library

<script type="text/javascript" src="jquery.min.js" charset="utf-8"></script> 

4. Javascript

$(function(){
	
	var menu = $('#menu'),
		pos = menu.offset();
		
		$(window).scroll(function(){
			if($(this).scrollTop() > pos.top+menu.height() && menu.hasClass('default')){
				menu.fadeOut('fast', function(){
					$(this).removeClass('default').addClass('fixed').fadeIn('fast');
				});
			} else if($(this).scrollTop() <= pos.top && menu.hasClass('fixed')){
				menu.fadeOut('fast', function(){
					$(this).removeClass('fixed').addClass('default').fadeIn('fast');
				});
			}
		});

});

This awesome jQuery plugin is developed by unknown. For more Advanced Usages, please check the demo page or visit the official website.