How i can fix my sidenav while body scrolling

199 Views Asked by At

How i can fix my sidenav while body scrolling when i scroll down my sidenav bottom gets empty

enter image description here

1

There are 1 best solutions below

0
On

  var header = $("#menu");
  $(window).scroll(function() {    
    var scroll = $(window).scrollTop();
       if (scroll >0) {
          header.addClass("fixed");
        } else {
          header.removeClass("fixed");
        }
});
 .fixed{
    position: fixed !important;
  }
  .c {
    height: 100vh;
    position: relative;
    padding: 50px;
}
div#menu {
    position: absolute;
    padding: 20px;
    background: #2196F3;
    color: ghostwhite;
    width: 200px;
    z-index: 1;
    height: 100vh;
}
.c {
    height: 100vh;
    padding: 50px;
    margin-left: 300px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="width: 100%">
  <div class="nav" id="menu">
    <h2>Menu</h2>
  </div>
  <div class="c">
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </div>
</div>