Created
June 15, 2015 23:38
-
-
Save benweiser/8dc2122aabe2c7bc4006 to your computer and use it in GitHub Desktop.
Genesis Sticky Top Bar Reveal JavaScript
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
| 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