我在使用 Bootstrap 3 的手风琴时遇到了一些问题。
我想要做的是向手风琴切换添加一个类,然后滚动/跳转到那个新添加的类。添加/删除类工作正常,我想我会在同一个块中添加一个 scrollTop ......但没有这样的运气。我错过了什么?
这是它的设置方式:
面板链接:
<ul>
<li><a data-toggle="collapse" data-parent="#accordion" href="#panel1">Panel1</a>
</li>
<li><a data-toggle="collapse" data-parent="#accordion" href="#panel2">Panel2</a>
</li>
<li>
<a data-toggle="collapse" data-parent="#accordion" href="#panel3" ">Panel3</a></li>
</ul>
面板:
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle aWeight active" data-toggle="collapse" data-parent="#accordion" href="#panel1">
Panel 1
</a>
</h4>
</div>
<div id="panel1" class="panel-collapse collapse in">
<div class="panel-body">Anim pariatur...</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle aFitness" data-toggle="collapse" data-parent="#accordion" href="#panel2">
Panel 2
</a>
</h4>
</div>
<div id="panel2" class="panel-collapse collapse">
<div class="panel-body">Anim pariatur...</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a class="accordion-toggle aFitness" data-toggle="collapse" data-parent="#accordion" href="#panel3">
Panel 3
</a>
</h4>
</div>
<div id="panel3" class="panel-collapse collapse">
<div class="panel-body">Anim pariatur...</div>
</div>
</div>
</div>
最后我使用这个脚本来切换活动类:
$(function () {
$('.accordion').on('show', function (e) {
$(e.target).prev('.accordion-heading').find('.accordion-toggle').addClass('active');
});
$('.accordion').on('hide', function (e) {
$(this).find('.accordion-toggle').not($(e.target)).removeClass('active');
});
});