twitter-bootstrap-3scrollaffix

Bootstrap, affix only after a certain scroll point


I'm using bootstrap with bootstrap-toc (https://afeld.github.io/bootstrap-toc/)

Working with the following scenario:

http://jsbin.com/cerozeleya/edit?output (make sure to click "run with Js" to be able to see the sidebar)

As I scroll the view, I would like the sidebar to scroll until a point where the jumbotron is no longer in view. At that point, it should stay affixed while the content scrolls.

I can't get that behaviour to happen with the included jsbin. I tried messing with the data-offset-top/data-offset-bottom attributes within my nav #toc but nothing changes. I found another question here that instructed the following changes on the css:

.affix{ top: 0px;}
.affix-bottom{ position: absolute;}

But that didn't work either. I tried reading the affix and scrollspy documentation, but its either not clicking with me, or I'm not seeing what I'm doing wrong.

Any help appreciated. Thanks!


Solution

  • You have to use data offset top within the tag which you want to affixed

    data-spy="affix" data-offset-top="197"
    

    Eg.

    <nav id="toc" data-toggle="toc" data-spy="affix" data-offset-top="197"></nav>
    

    Edit the offset value according to your needs