javascript - fixed sticky header expanding -


i have following issue. trying make fixed header on top. page responsive , when screen small header if clicked expands pushing down content... issue can't find solution make work.. either put position:fixed; , header stays on top, content not pushed down... if position relative content gets pushed down header not stick top. there solution this? possibly css if not javascript..

css:

.header {     width: 100%;     height: inherit;     margin-bottom: 5px;     float: left;     position: fixed;     z-index: 999;     top: 0;     left: 0;     background: #f3f3f3;         -webkit-box-shadow: 0px 1px 1px #000;     -moz-box-shadow: 0px 1px 1px #000;     box-shadow: 0px 1px 1px #000; } 

javascript:

function showmobilebar(){             $(menu).hide(0);             $(showhidebutton).show(0).click(function(){                 if($(menu).css("display") == "none")                     $(menu).slidedown(settings.showspeed);                  else                     $(menu).slideup(settings.hidespeed).find(".dropdown, .megamenu").hide(settings.hidespeed);             });         }          // hide bar show/hide menu items on mobile         function hidemobilebar(){             $(menu).show(0);             $(showhidebutton).hide(0);         } 

html:

<div class="content">             <header id="menuzord" class="menuzord blue">     <h1>         <a href="/" class="menuzord-brand">             <img src="{% static 'img/logo.png' %}" alt="logo"/>         </a>     </h1>     <a href="/admin/"/>admin</a>     <ul class="menuzord-menu">         <li class="active">         </li>         <li class="active"><a href="#"><i class="fa fa-minus-circle"></i></a></li>             {% endif %} -->             <li class="active">             </li>             <li class="active">             </li>             <li class="active">             </li>{% csrf_token %}             <li class="active">             </li>     </ul>        </header>             <div class="container">             <div class ="main">                 <div class="side">                     <p>sidebar</p>                 </div>             </div>             </div> </div> 

thanks

well, link provided has different code used. solve issue in link provided, need several things.

css:

.nav {     position: fixed; } .header {     margin-top: 55px; /* height of fixed nav bar */ }  @media (max-width: 900px) {     .header {         margin-top: 59px; /* height of fixed nav bar smaller sizes */     } } 

javascript: (updated jquery code that's on site - $(".btmenu").click() function)

$(".btmenu").click(function(){     if($(".menu").children(".menuitem").css("display") == "none"){         $(".menu").children(".menuitem").slidedown();         var menuheight = $(".menu").height(); // added - height of menu after has been expanded         $(".header").animate({ margintop: menuheight + "px" }, 400); // animate margin @ same speed of slide, match new header height     }     else{         $(".menu").children(".menuitem").slideup();         var menuheight = $(".menu").height(); // added - height of menu after has been collapsed         $(".header").animate({ margintop: menuheight + "px" }, 400); // animate margin @ same speed of slide, match new header height     } }); 

this several things.

first, css fixes header top, , sets margin of header match height of nav bar (they different depending on screen width).

since javascript opening menu, can calculate new nav height (after event of opening or closing menu), , set new margin (with same animation speed) header. haven't tested this, logic you'll need. if there delay, may need work animate , slidedown bit.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -