Fixed nav-bar dissapearing after scroll up

Fixed nav-bar dissapearing after scroll up

Hi!I am having a problem which I don't know how to fix anymore.I have a nav-bar which i would like to make it fixed on scroll.I have the following code:
  1. <div class="nav-placeholder"></div>
  2.     <nav class="nav-bar" role="navigation" >
  3.       <div class="wrapper">
  4.         <div class="medium-down--hide">
  5.           {% comment %}
  6.             List out your main-menu linklist (default)

  7.             More info on linklists:
  8.               - http://docs.shopify.com/themes/liquid-variables/linklists
  9.           {% endcomment %}
  10.           <!-- begin site-nav -->
  11.           <ul class="site-nav" id="AccessibleNav">
  12.             {% for link in linklists.main-menu.links %}
  13.               {% comment %}
  14.                 Create a dropdown menu by naming a linklist the same as a link in the parent nav

  15.                 More info on dropdowns:
  16.                   - http://docs.shopify.com/manual/your-website/navigation/create-drop-down-menu
  17.               {% endcomment %}
  18.               {% assign child_list_handle = link.title | handleize %}
  19.               {% if linklists[child_list_handle].links != blank %}
  20.                 <li class="site-nav--has-dropdown{% if link.active %} site-nav--active{% endif %}" aria-haspopup="true">
  21.                   <a href="{{ link.url }}" class="site-nav__link">
  22.                     {{ link.title }}
  23.                     <span class="icon icon-arrow-down" aria-hidden="true"></span>
  24.                   </a>
  25.                   <ul class="site-nav__dropdown">
  26.                     {% for childlink in linklists[child_list_handle].links %}
  27.                       <li{% if childlink.active %} class="site-nav--active"{% endif %}>
  28.                         <a href="{{ childlink.url }}" class="site-nav__link">{{ childlink.title | escape }}</a>
  29.                       </li>
  30.                     {% endfor %}
  31.                   </ul>
  32.                 </li>
  33.               {% else %}
  34.                 <li {% if link.active %}class="site-nav--active"{% endif %}>
  35.                   <a href="{{ link.url }}" class="site-nav__link">{{ link.title }}</a>
  36.                 </li>
  37.               {% endif %}
  38.             {% endfor %}
  39.           </ul>
  40.           <!-- //site-nav -->
  41.         </div>
  42.         <div class="large--hide medium-down--show">
  43.           <div class="grid">
  44.             <div class="grid__item one-half">
  45.               <div class="site-nav--mobile">
  46.                 <button type="button" class="icon-fallback-text site-nav__link js-drawer-open-left" aria-controls="NavDrawer" aria-expanded="false">
  47.                   <span class="icon icon-hamburger" aria-hidden="true"></span>
  48.                   <span class="fallback-text">{{ 'layout.navigation.menu' | t }}</span>
  49.                 </button>
  50.               </div>
  51.             </div>
  52.             <div class="grid__item one-half text-right">
  53.               <div class="site-nav--mobile">
  54.                  <a class="cart" href="/cart">
  55.       <a href="/cart" class="js-drawer-open-right site-nav__link" aria-controls="CartDrawer" aria-expanded="false">
  56.                  
  57.                      {% include 'svg-cart' %}{% if cart.item_count > 0 %}<div style="display:inline-block;position:absolute;font-weight:bold;">{{ cart.item_count }}</div>{% endif %}
  58.                   
  59.                 </a>
  60.        
  61.       </a>
  62.               </div>
  63.             </div>
  64.           </div>
  65.         </div>
  66.       </div>
  67.     </nav>
My target in the "nav-bar" element which I make it fixed with Jquery as follows:
  1.  </script>
  2.               <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
  3.               <script>
  4.            $(document).scroll(function() {
  5.     var y = $(document).scrollTop(), //get page y value 
  6.         header = $(".nav-bar"); // your div id
  7.     if(y >= 100)  {
  8.        $(".nav-placeholder").height($(".nav-bar").outerHeight());
  9.         header.css({position: "fixed", "top" : "0", "left" : "0"});
  10.     } else {
  11.       $(".nav-placeholder").height(0);
  12.         header.css("position", "static");
  13.     }
  14. });
              </script>

I have made a separate div "nav-placeholder" in order to help the "nav-bar" become fixed and the following css for the nav-bar :
  1. .nav-bar {
  2.   background-color: #116466;
  3.   font-family:"Diverplate";
  4.   text-transform:uppercase;
  5.   font-weight:bold;
  6.   z-index:99999;
  7.   overflow-x: auto;
  8.   height:80px;
  9. width:100%;
  10.   position:static;
  11. }
My problem is in the fact that every time I scroll up and the nav-bar reaches the top of the screen,it just vanishes.I have already set the z-index as I thought initially this might be the issue along with a height for it and also the top of the header that is above it to 0.I have also set the top of the content as the nav-bar was initially covering it's title when I set position:fixed.I have tried almost everything I found on the internet but nothing worked as it won't stay fixed at all on the screen.I don't have any ideas left so I would really appreciate if you can share your thoughts on why this might not be working.Best regards//