Skip to content

Instantly share code, notes, and snippets.

@benstjohn
Created February 28, 2016 04:58
Show Gist options
  • Save benstjohn/cf6f37ecd8454d12fc0e to your computer and use it in GitHub Desktop.
Save benstjohn/cf6f37ecd8454d12fc0e to your computer and use it in GitHub Desktop.
Makes a nav bar appear when scrolling upward
var position = $(window).scrollTop(); // should start at 0
$(window).scroll(function() {
var scroll = $(window).scrollTop();
var el = document.getElementById('topbar');
var soc = document.getElementById('social');
var nav = document.getElementById('navlinks');
console.log('scroll');
if(scroll > position) {
// scrolling downwards
console.log ( 'DownScroll' );
el.style.backgroundColor = 'transparent';
soc.style.visibility = 'hidden';
nav.style.visibility = 'hidden';
} else {
// scrlling upwards
console.log ( 'Upscroll' );
el.style.backgroundColor = "#0cb189";
soc.style.visibility = 'visible';
nav.style.visibility = 'visible';
}
if (scroll == 0) {
soc.style.visibility = 'visible';
nav.style.visibility = 'visible';
el.style.backgroundColor = 'transparent';
};
position = scroll;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment