0

I have an active sidebar navigation, which is not moving up with all the website content when you scroll down the page.

My problem is, that it is working the way I want it to work on a desktop browser, but it jumps up and down and doesn't allow any scrolling as soon as I decrease the browser size or run it as a mobile preview (Chrome Developer Tools)

Here is a: jsfiddle, which unfortunately doesn't work. But the code below works fine! You can just copy it into an html file.

<!DOCTYPE html>
<html>

<head>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<!-- Bootstrap -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>
<!-- Side Navbar -->
  <div class="container">
    <div class="row">
      <!--left-->
      <div class="col-md-3" id="leftCol">
        <ul class="nav nav-stacked" id="sidebar">
          <li>
            <div id="sideBarLogo">
              <a href="#">
                <img class="img-responsive" style="display:inline-block; height:120px; margin-top:200px" src="images/logo.png" alt="Logo">
                <br><br><br><br>
              </a>
            </div>
          </li>
          <li><a href="#sec0"><p class="raleway">Menu 1</p></a></li>
          <li><a href="#sec1"><p class="raleway">Menu 2</p></a></li>
          <li><a href="#sec2"><p class="raleway">Menu 3</p></a></li>
          <li><a href="#sec3"><p class="raleway">Menu 4</p></a></li>
          <li><a href="#sec4"><p class="raleway">Menu 5</p></a></li>
        </ul>
      </div>
      <!--/left-->

      <!--right-->
      <div class="col-md-9">
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <br><br><br><br><br>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <br><br><br><br><br>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <br><br><br><br><br>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <br><br><br><br><br>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <br><br><br><br><br>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <br><br><br><br><br>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <p>text text text</p>
        <br><br><br><br><br>
      </div>
    </div>
  </div>

</body>

</html>

<script>
  /* activate sidebar */
$('#sidebar').affix({
  offset: {
    top: 235
  }
});
</script>

If somebody knows a solution, I appreciate it alot. Many thank in advance!

Manish Patel
  • 3,648
  • 1
  • 14
  • 22
sunwarr10r
  • 4,420
  • 8
  • 54
  • 109
  • You need CSS to handle the affixed element because it's position: fixed and moves out of the normal document flow: http://stackoverflow.com/a/21029328/171456 – Carol Skelly Apr 10 '17 at 12:08
  • Thank you @ZimSystem! Now the sidebar navigation is not jumping up and down anymore, but instead in hides behind the right column content as soon as the browser size is decreased. I want the menu to go above the content. – sunwarr10r Apr 10 '17 at 14:07

0 Answers0