ブートストラップ4JS折りたたみ


CSSクラスを折りたたむ

折りたたみ可能なチュートリアルについては、ブートストラップ折りたたみチュートリアルをお読みください。

Class Description Example
.collapse Hides the content
.collapse show Shows the collapsible content by default
.collapsing Added when the transition starts, and removed when it finishes

データ経由-*属性

data-toggle="collapse"data-targetto要素を追加するだけで、折りたたみ可能な要素の制御を自動的に割り当てることができます。data-target属性は、折りたたみを適用するCSSセレクターを受け入れます。折りたたみ可能な要素にクラスcollapseを追加してください。デフォルトで開く場合は、クラス「show」を追加します。

<button class="btn" data-toggle="collapse" data-target="#demo">Collapsible</button>

<div id="demo" class="collapse">
Some text..
</div>

ヒント:折りたたみ可能なコントロールにアコーディオンのようなグループ管理を追加するには、データ属性data-parent = "#selector"を追加します。


JavaScript経由

次のコマンドで手動で有効にします。

$('.collapse').collapse()

折りたたみオプション

オプションは、データ属性またはJavaScriptを介して渡すことができます。データ属性の場合、data-parent = ""のように、オプション名をdata-に追加します。

Name Type Default Description Try it
parent selector false All collapsible elements under the specified parent will be closed when this collapsible item is shown. (similar to traditional accordion behavior)
toggle boolean true Toggles the collapsible element on invocation

折りたたみメソッド

次の表に、使用可能なすべての折りたたみメソッドを示します。

Method Description Try it
.collapse(options) Activates the collapsible element with an option. See options above for valid values
.collapse("toggle") Toggles the collapsible element
.collapse("show") Shows the collapsible element
.collapse("hide") Hides the collapsible element
.collapse("dispose") Destroys the collapsible element

折りたたみイベント

次の表に、使用可能なすべての折りたたみイベントを示します。

Event Description Try it
show.bs.collapse Occurs when the collapsible element is about to be shown
shown.bs.collapse Occurs when the collapsible element is fully shown (after CSS transitions have completed)
hide.bs.collapse Occurs when the collapsible element is about to be hidden
hidden.bs.collapse Occurs when the collapsible element is fully hidden (after CSS transitions have completed)