sticky menu

  • Posted in : Bloggy WP
  • Eloen
    Participant

    How can I make the menu become sticky when scrolling down a page and not just when scrolling up?

    ahmetsali
    Keymaster

    Hi, edit js/main.js in theme folder, and find line : 14, you will see;

    //**********************************
    		// FIXED NAV MENU
    		var isFixedNav = $('html').attr("data-fixed-nav") == "true";
    		if(isFixedNav) {
    			var navMenu = $('#site-navigation');
    			var navMenuTop = navMenu.position().top - navMenu.height();
    			
    			var scrolled = $(window).scrollTop();
    			
    			$(window).bind('scroll', function() {
    				
    				//console.log($(window).scrollTop());
    				
    				 if ($(window).scrollTop() > navMenuTop ) {
    					 navMenu.addClass('fixed');
    					 // user is scrolling top : show fixed menu
    					 if(scrolled > $(window).scrollTop()) {
    					 	navMenu.stop(true,true).slideDown(100);
    					 } else {
    						navMenu.stop(true,true).slideUp(100); 
    						$('.header-search').hide();
    					 }
    				 }
    				 else {
    					 navMenu.removeClass('fixed');
    				 }
    				 
    				 scrolled = $(window).scrollTop();
    			});
    		}
    		//**********************************
    

    replace it with this;

    //**********************************
    		// FIXED NAV MENU
    		var isFixedNav = $('html').attr("data-fixed-nav") == "true";
    		if(isFixedNav) {
    			var navMenu = $('#site-navigation');
    			var navMenuTop = navMenu.position().top - navMenu.height();
    			
    			var scrolled = $(window).scrollTop();
    			
    			$(window).bind('scroll', function() {
    				
    				//console.log($(window).scrollTop());
    				
    				 if ($(window).scrollTop() > navMenuTop ) {
    					 navMenu.addClass('fixed');
    					 // user is scrolling top : show fixed menu
    					 
    					 	navMenu.show();
    					
    				 }
    				 else {
    					 navMenu.removeClass('fixed');
    				 }
    				 
    				 scrolled = $(window).scrollTop();
    			});
    		}
    		//**********************************
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in and have valid license to reply to this topic.

License required for the following item
Login and Registration Log in · Register