Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. // Hide Header on on scroll down
  2. var didScroll;
  3. var lastScrollTop = 0;
  4. var delta = 5;
  5. var navbarHeight = $('header').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. $('header').removeClass('nav-down').addClass('nav-up');
  30. } else {
  31. // Scroll Up
  32. if(st + $(window).height() < $(document).height()) {
  33. $('header').removeClass('nav-up').addClass('nav-down');
  34. }
  35. }
  36.  
  37. lastScrollTop = st;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement