Skip to content

Instantly share code, notes, and snippets.

@nagelflorian
Created December 4, 2014 22:52
Show Gist options
  • Save nagelflorian/a7883a97cd6b4c658faf to your computer and use it in GitHub Desktop.
Save nagelflorian/a7883a97cd6b4c658faf to your computer and use it in GitHub Desktop.
Scroll based navigation bar (inspired by Teehan+Lax)
var lastScrollY = 0,
minScroll = 20,
delay = 150;
var navMovement = setInterval(function() {
var nav = document.getElementById('nav')
var scrollY = document.all? iebody.scrollTop : pageYOffset;
if(scrollY + minScroll < lastScrollY || scrollY <= 25) {
nav.style.top = "0px"
} else if (scrollY > lastScrollY){
nav.style.top = - nav.offsetHeight + "px"
}
lastScrollY = scrollY;
}, delay);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment