kalponikoronno

jquery for sticky menu

Feb 19th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(document).ready(function($) {  
  2.  
  3.     /* Stick navigation to the top of the page */
  4.     var stickyNavTop = $('.main-navigation').offset().top;
  5.  
  6.     $(window).scroll(function(){  
  7.         var scrollTop = $(window).scrollTop();  
  8.  
  9.         if (scrollTop > stickyNavTop) {  
  10.             $('.main-navigation').addClass('sticky-header');
  11.             $('.site-header').addClass('shifted');
  12.         } else {  
  13.             $('.main-navigation').removeClass('sticky-header');  
  14.             $('.site-header').removeClass('shifted');
  15.         }  
  16.  
  17.     });
  18.  
  19. /* Scroll to specific section on front page */
  20.         $(function() {
  21.             $('a[href*=#]:not([href=#])').click(function() {
  22.                 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
  23.                     var target = $(this.hash);
  24.                     target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
  25.                     if (target.length) {
  26.                         $('html,body').animate({
  27.                             scrollTop: (target.offset().top - 80)
  28.                         }, 1000);
  29.                         return false;
  30.                     }
  31.                 }
  32.             });
  33.         });
  34.  
  35. });
Advertisement
Add Comment
Please, Sign In to add comment