Last active
August 29, 2015 14:17
-
-
Save besimhu/4c58ec44826c3a0b9b62 to your computer and use it in GitHub Desktop.
Hides header when you scroll down and shows when you scroll back up. The animation is handled through CSS. You can simply use a transform to move the navigation off screen.
This file contains hidden or 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
function headerHide() { | |
// Hide Header on scroll down | |
var didScroll; | |
var lastScrollTop = 0; | |
var delta = 5; | |
var navbarHeight = $('.header-global').outerHeight(); | |
$(window).scroll(function(event){ | |
didScroll = true; | |
}); | |
setInterval(function() { | |
if (didScroll) { | |
hasScrolled(); | |
didScroll = false; | |
} | |
}, 250); | |
function hasScrolled() { | |
var st = $(this).scrollTop(); | |
// Make sure they scroll more than delta | |
if(Math.abs(lastScrollTop - st) <= delta) | |
return; | |
// If they scrolled down and are past the navbar, add class .is-up | |
// This is necessary so you never see what is "behind" the navbar. | |
if (st > lastScrollTop && st > navbarHeight){ | |
// Scroll Down | |
$('.header-global').removeClass('is-down').addClass('is-up'); | |
} else { | |
// Scroll Up | |
if(st + $(window).height() < $(document).height()) { | |
$('.header-global').removeClass('is-up').addClass('is-down'); | |
} | |
} | |
lastScrollTop = st; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment