Created
February 28, 2016 04:58
-
-
Save benstjohn/cf6f37ecd8454d12fc0e to your computer and use it in GitHub Desktop.
Makes a nav bar appear when scrolling upward
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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