부트스트랩 4 JS 축소


CSS 클래스 축소

Collapsibles에 대한 튜토리얼은 Bootstrap Collapse 튜토리얼 을 읽어보세요 .

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 선택기를 허용합니다. 접을 수 있는 요소에 클래스 축소를 추가해야 합니다. 기본적으로 열리려면 "show" 클래스를 추가하세요.

예시

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

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

팁: 접을 수 있는 컨트롤에 아코디언과 같은 그룹 관리를 추가하려면 데이터 속성 data-parent="#selector"를 추가하세요.


자바스크립트를 통해

다음을 사용하여 수동으로 활성화:

$('.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)