Advertisement
Guest User

Untitled

a guest
Jul 9th, 2014
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Hide second header on on scroll down
  2. var didScroll;
  3. var lastScrollTop = 0;
  4. var delta = 5;
  5. var navbarHeight = $('.navigation').outerHeight();
  6.  
  7. $(window).scroll(function(event){
  8.     didScroll = true;
  9. });
  10.  
  11. setInterval(function() {
  12.     if (didScroll) {
  13.         hasScrolled();
  14.         didScroll = false;
  15.     }
  16. }, 250);
  17.  
  18. function hasScrolled() {
  19.     var st = $(this).scrollTop();
  20.    
  21.     // Make sure they scroll more than delta
  22.     if(Math.abs(lastScrollTop - st) <= delta)
  23.         return;
  24.    
  25.     // If they scrolled down and are past the navbar, add class .nav-up.
  26.     // This is necessary so you never see what is "behind" the navbar.
  27.     if (st > lastScrollTop && st > navbarHeight){
  28.         // Scroll Down
  29.         $('.navigation').removeClass('.navigation').addClass('nav-up');
  30.     } else {
  31.         // Scroll Up
  32.         if(st + $(window).height() < $(document).height()) {
  33.             $('.navigation').removeClass('nav-up').addClass('.navigation');
  34.         }
  35.     }
  36.    
  37.     lastScrollTop = st;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement