Skip to content

Instantly share code, notes, and snippets.

@GochoMugo
Created July 7, 2014 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GochoMugo/540774512e337b935e0b to your computer and use it in GitHub Desktop.
Save GochoMugo/540774512e337b935e0b to your computer and use it in GitHub Desktop.
A Pen by GOCHO MUGO I..
<div class="filler one"></div>
<nav id="navbar">
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</nav>
<div class="filler two"></div>
(function($, undefined){
"use strict";
var $navbar = $("#navbar"),
y_pos = $navbar.offset().top,
height = $navbar.height();
$(document).scroll(function(){
var scrollTop = $(this).scrollTop();
if (scrollTop > y_pos + height){
$navbar.addClass("navbar-fixed").animate({ top: 0 });
} else if (scrollTop <= y_pos){
$navbar.removeClass("navbar-fixed").clearQueue().animate({ top: "-48px" }, 0);
}
});
})(jQuery, undefined);
.navbar-fixed {
position: fixed;
top: -48px;
}
/*----------------------
$NAVBAR
basic navbar styling
----------------------*/
nav {
width: 100%;
color: #bbb;
background: #2e2e2e;
font-weight: bold;
letter-spacing: 0.025em;
}
nav ul {
text-align: center;
margin: 0;
}
nav ul li {
display: inline-block;
padding: 0 3em 0 3em;
line-height: 3em;
}
nav ul li:hover {
background: #00939C;
}
/*----------------------
$BODY
----------------------*/
body {
background: #0B6AD4;
}
/*----------------------
$MISC
----------------------*/
.filler {
width: 1px;
height: 200px;
}
.two {
height: 3000px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment