jquery - Javascript show/hide menu on scroll with a twist -


here demo of menu fadein:

fiddle demo

i seeking advice on tricky show hide problem have. menu fades in @ point using following:

$(window).scroll(function () {    var d = $('#menu');      if (d.offset().top > 810) {        d.fadein();     } else {        d.stop().hide();     } }); 

what need 1 of links within menu not hidden , show @ top of page , remain once menu appears other links.

the menu displays following:

<div id="menu">      <div class="top-bar">          <div class="container">              <div>                 <a href="index.php" class="top-bar-brand">mywebsite</a>                               </div>              <nav>                 <ul class="navbar-right">                     <li><a href="">buy now</a></li>                     <li><a href="">link2</a></li>                     <li><a href="">link2</a></li>                     <li><a href="">login</a></li>                 </ul>               </nav>             </div>      </div>  </div>   #menu {     width : 100%;     height : auto;     overflow: auto;     position: fixed;     display : none;     background-color: rgba(255, 255, 255, 0.9);     z-index: 999999; } 

so link called 'login' need show @ times other links , background color of menu shows on scroll , hides again 'login' link remains.

i tried this, see if wanted jsfiddle updated

    <div id="menu">      <div class="top-bar">          <div class="container">              <div>                 <a href="index.php" class="top-bar-brand hideme">schoolshare</a>                               </div>              <nav>                 <ul class="navbar-right">                     <li class="hideme"><a href="">buy now</a></li>                     <li class="hideme"><a href="">parents</a></li>                     <li class="hideme"><a href="">schools</a></li>                     <li><a href="">login</a></li>                 </ul>               </nav>             </div>      </div>  </div> </div>  <div class="bodydiv">scroll down</div> 

the javascript

$('.hideme').hide(); $(window).scroll(function () {    var d = $('#menu');      if (d.offset().top > 810) {        $('.hideme').fadein();         $('#menu').css({'background':'rgba(255,255,255,0.9)'});     } else {        $('.hideme').fadeout();         $('#menu').css({'background':'rgba(255,255,255,0)'});     } }); 

the css

#menu {     width : 100%;     height : auto;     overflow: auto;     position: fixed;     z-index: 999999; }  .top-bar{     width:100%;     overflow:auto;     height:auto;     padding: 10px 0; }  .top-bar-brand{     float:left;     font-size:18px;     color: #2c3e50;     display: block;     -webkit-margin-before: 1em;     -webkit-margin-after: 1em;     -webkit-margin-start: 0px;     -webkit-margin-end: 0px;     -webkit-padding-start: 10px; }  nav{     float:right;         height: 100%;     margin: 0;     padding: 4px 0 0 0; }  .navbar-right{ }  .navbar-right ul{     padding: 0;     list-style:none; }  .navbar-right li{     display:inline-block;     margin: 0 10px; }  body{background-color: #ddd;}  .bodydiv{height: 2000px;} .hideme {     display: none; } #menu {     -webkit-transition: background 500ms ease;     -moz-transition: background 500ms ease;     -o-transition: background 500ms ease;     transition: background 500ms ease; } 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -