Bootstrap 3 Scrollspy无法使用Affix和Panel

时间:2013-12-11 18:08:02

标签: jquery css twitter-bootstrap scrollspy

我正在尝试将引导程序ScrollSpy应用到我的词缀导航栏。有一些我想念的东西因为我认为我已经做好了一切。

这是我的代码:

        <script type='text/javascript' src="//code.jquery.com/jquery.js"></script>
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">
        <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>

<div class="container">
        <div class="row">
            <div class="col-md-2">
              <div id="sidebar">
                    <ul class="nav navbar-default affix">
                        <li><a href="#correct">Correct</a></li>
                        <li><a href="#incorrect">Incorrect</a></li>
                        <li><a href="#omission">Omission</a></li>
                        <li><a href="#premature">Premature</a></li>
                    </ul>
                </div>
            </div>


            <div id="mycontent" class="col-md-10" data-spy="scroll" data-target="#sidebar">

                    <div id="correct" class="panel panel-primary">
                        <div class="panel-heading">
                            <h3 class="panel-title">Correct responses</h3>
                        </div>
                        <div class="panel-body">        
                            <h4>Graphic</h4>
                                <img src="/graph/group/post-op/lineerror/12/correct" onerror="imgError(this);"> 
                             <h4>Table</h4> 
                               Table here 
                        </div>
                    </div>

                    <div id="incorrect" class="panel panel-primary">
                        <div class="panel-heading">
                            <h3 class="panel-title">Incorrect responses</h3>
                        </div>
                        <div class="panel-body">        
                            <h4>Graphic</h4>
                                <img src="/graph/group/post-op/lineerror/12/incorrect" onerror="imgError(this);"> 
                             <h4>Table</h4> 
                               Table here 
                        </div>
                    </div>

                    <div id="omission" class="panel panel-primary">
                        <div class="panel-heading">
                            <h3 class="panel-title">Omission responses</h3>
                        </div>
                        <div class="panel-body">        
                            <h4>Graphic</h4>
                                <img src="/graph/group/post-op/lineerror/12/omission" onerror="imgError(this);"> 
                             <h4>Table</h4> 
                               Table here 
                        </div>
                    </div>

                    <div id="premature" class="panel panel-primary">
                        <div class="panel-heading">
                            <h3 class="panel-title">Premature responses</h3>
                        </div>
                        <div class="panel-body">        
                            <h4>Graphic</h4>
                                <img src="/graph/group/post-op/lineerror/12/premature" onerror="imgError(this);"> 
                             <h4>Table</h4> 
                               Table here 
                        </div>
                    </div>
              </div>
        </div>          
    </div>  

我的链接和我的词缀工作正常,但我看不到卷轴。

查看改编后的jsfiddle here

1 个答案:

答案 0 :(得分:5)

  

&#34;要轻松地将scrollspy行为添加到您的顶部栏导航,请将data-spy="scroll"添加到您要侦听的元素(最常见的是<body>)。然后添加data-target属性,其中包含任何Bootstrap .nav组件的父元素的ID或类。&#34; - docs

必须将这些data-属性添加到正在滚动的元素中。除非#mycontentoverflow:scroll,否则您需要将这些data-属性添加到<body>代码中。

http://jsfiddle.net/mblase75/qKFqg/