我正在尝试在可折叠面板中使用Bootstrap Scrollspy。一切似乎都在起作用,除非我点击它们时药丸不会更新/改变颜色。我想我必须改变CSS,但我不确定我需要改变什么。
HTML
<body>
<div class="container">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">
Title 1
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
<div class="row">
<nav class="col-sm-3" id="myScrollspy">
<ul class="nav nav-pills nav-stacked">
<li class="active"><a href="#Subtitle1">Subtitle1</a></li>
<li><a href="#Subtitle2">Subtitle2</a></li>
<li><a href="#Subtitle3">Subtitle3</a></li>
<li><a href="#Subtitle4">Subtitle4</a></li>
<li><a href="#Subtitle5">Subtitle5</a></li>
<li><a href="#Subtitle6">Subtitle6</a></li>
<li><a href="#Subtitle7">Subtitle7</a></li>
</ul>
</nav>
<div class="col-sm-9">
<div id="Subtitle1">
<h1>Subtitle1</h1>
<p>some text</p>
</div>
<div id="Subtitle2">
<h1>Subtitle2</h1>
<p>some text</p>
</div>
<div id="Subtitle3">
<h1>Subtitle3</h1>
<p>some text</p>
</div>
<div id="Subtitle4">
<h1>Subtitle4</h1>
<p>some text</p>
</div>
<div id="Subtitle5">
<h1>Subtitle5</h1>
<p>some text</p>
</div>
<div id="Subtitle6">
<h1>Subtitle6</h1>
<p>some text</p>
</div>
<div id="Subtitle7">
<h1>Subtitle7</h1>
<p>some text</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
Title 2
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse">
<div class="panel-body">
Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo.
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle = "collapse" data-parent = "#accordion" href = "#collapseThree">
Title 3
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse">
<div class="panel-body">
Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo.
</div>
</div>
</div>
</div>
</div>
<!-- /container -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
CSS
body {
position: relative;
}
ul.nav-pills {
top: 50px;
position: fixed;
}
div.col-sm-9 div {
height: 250px;
font-size: 28px;
}
答案 0 :(得分:0)
您忘记在第一个body标记上添加一些自定义引导属性。这将使药丸按钮突出显示,虽然你很快就会发现你会遇到另一个小问题。突出显示的状态将跳过最后两个按钮,从4到7,因为滚动条将快速到达浏览器的底部。我想这会有点棘手。它还取决于每个部分文本的长度
HTML:
<body data-spy="scroll" data-target="#myScrollspy">
答案 1 :(得分:0)
我使用了推荐的自定义引导属性。
HTML
<body data-spy="scroll" data-target="#myScrollspy">
然后我改变了CSS中每个部分的高度来修复跳跃问题。
CSS
#Subtitle1,
#Subtitle2,
#Subtitle3,
#Subtitle4,
#Subtitle5,
#Subtitle6,
#Subtitle7 {
height: 500px;
}