Skip to content

Instantly share code, notes, and snippets.

@adrianjguerrero
Created July 10, 2019 12:38
Show Gist options
  • Save adrianjguerrero/96ec6512624b396241b0e668954f06a3 to your computer and use it in GitHub Desktop.
Save adrianjguerrero/96ec6512624b396241b0e668954f06a3 to your computer and use it in GitHub Desktop.
function to hide a nav on scroll down, then show it on scroll up
function hideNav(el, howMuch) {
var prevScrollpos = window.pageYOffset;
window.addEventListener('scroll', function () {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
el.style.transform = 'translateY(0%)'
} else {
el.style.transform = 'translateY(' + howMuch + '%)'
}
prevScrollpos = currentScrollPos;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment