How to use Bootstrap scroll spy?

前端 未结 8 562
眼角桃花
眼角桃花 2020-12-08 02:52

I cannot quite get the scroll spy to work properly with a vertical nav. Below you can find the code I use. For some reason, only \"Two\" gets active.

Anyone has an i

相关标签:
8条回答
  • 2020-12-08 03:45

    I did it like this. for data target I use the class name .navbar

          <body data-spy="scroll" data-target=".navbar" data-offset="50">
           <nav class="navbar navbar-default navbar-fixed-top" >
    
    0 讨论(0)
  • 2020-12-08 03:51

    In sorting this out for myself, I've found that the element being spied upon needs to have a scroll bar.

    Take a look at this Fiddle: http://jsfiddle.net/adamp/qgU6h/1/

    You can either spy directly on the body element ($('body').scrollspy()) or give your content an explicit height and force it to show a scrollbar.

    (If you look at the Bootstrap documentation example, it does the fixed-height trick.)

    0 讨论(0)
提交回复
热议问题