jquery.js 1.10.2 と bootstrap-collapse.js v2.3.0 を使用して、これは上記の焼き直しです。ドキュメントをロードすると、最初のアイテムを除くすべてのアイテムが折りたたまれ、その後の表示/非表示イベントが処理されます。
$(document).ready(function () {
$(".accordion-body").on("shown", function (evt) {
setIcon(evt.target, true);
});
$(".accordion-body").on("hidden", function (evt) {
setIcon(evt.target, false);
});
$(".accordion-body").collapse("hide");
$("#collapse-faq-1").collapse("show");
});
function setIcon(acdBody, isShown) {
var indicator = "indicator" + acdBody.id.substr(acdBody.id.lastIndexOf("-"));
if (!isShown) {
$("#" + indicator).removeClass("icon-chevron-up").addClass("icon-chevron-down");
} else {
$("#" + indicator).removeClass("icon-chevron-down").addClass("icon-chevron-up");
}
}
HTML:
<div class="accordion" id="accordion">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse-faq-1">
<i id="indicator-1" class="icon-chevron-down"></i>
FAQ Item 1
</a>
</div>
<div id="collapse-faq-1" class="accordion-body collapse in">
<div class="accordion-inner">
Answer 1 ...
</div>
</div>
</div>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapse-faq-2">
<i id="indicator-2" class="icon-chevron-down"></i>
FAQ Item 2
</a>
</div>
<div id="collapse-faq-2" class="accordion-body collapse in">
<div class="accordion-inner">
Answer 2 ...
</div>
</div>
</div>
</div>