Skip to content

Instantly share code, notes, and snippets.

@benweiser
Created June 15, 2015 23:38
Show Gist options
  • Select an option

  • Save benweiser/8dc2122aabe2c7bc4006 to your computer and use it in GitHub Desktop.

Select an option

Save benweiser/8dc2122aabe2c7bc4006 to your computer and use it in GitHub Desktop.
Genesis Sticky Top Bar Reveal JavaScript
jQuery(document).ready(function($) {
// Hide Top bar on on scroll down
var didScroll;
var lastScrollTop = 0;
var delta = 5;
var topbarHeight = $('.top-bar').outerHeight();
$(window).scroll(function(event){
didScroll = true;
});
setInterval(function() {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
function hasScrolled() {
var st = $(this).scrollTop();
if(Math.abs(lastScrollTop - st) <= delta)
return;
if (st > lastScrollTop && st > topbarHeight){
// Scroll Down
$('.top-bar').removeClass('bar-down').addClass('bar-up');
} else {
// Scroll Up
if(st + $(window).height() < $(document).height()) {
$('.top-bar').removeClass('bar-up').addClass('bar-down');
}
}
lastScrollTop = st;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment