방법 - 축소
접을 수 있는 섹션을 만드는 방법을 알아보세요.
접을 수 있는
축소 가능한 콘텐츠 표시 및 숨기기를 전환하려면 버튼을 클릭합니다.
일부 접을 수 있는 콘텐츠. 축소 가능한 콘텐츠 표시 및 숨기기를 전환하려면 버튼을 클릭합니다. 통증 자체도 중요하지만 아디피싱 과정에 의해 통증이 더 커지는데, 큰 일을 할 수 있도록 통증을 줄이는 시간을 드리고 있습니다. 대부분의 경우 우리 중 누구라도 고용의 목적을 활용하는 것을 제외하고는 모든 종류의 고용을 행사하게 될 것입니다.
축소 가능 만들기
1단계) HTML 추가:
예시
<button type="button" class="collapsible">Open Collapsible</button>
<div class="content">
<p>Lorem ipsum...</p>
</div>
2단계) CSS 추가:
아코디언 스타일 지정:
예시
/* Style the button that is used to open and close the
collapsible content */
.collapsible {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
}
/* Add a background color to the button if it is clicked on (add the
.active class with JS), and when you move the mouse over it (hover) */
.active, .collapsible:hover {
background-color: #ccc;
}
/* Style the
collapsible content. Note:
hidden by default */
.content {
padding: 0 18px;
display:
none;
overflow: hidden;
background-color: #f1f1f1;
}
3단계) 자바스크립트 추가:
예시
var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click",
function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.display
=== "block") {
content.style.display =
"none";
} else {
content.style.display = "block";
}
});
}
애니메이션 축소 가능(슬라이드 다운)
애니메이션을 접을 수 있게 하려면 클래스 에 max-height 속성에 대해 및 a max-height: 0
를 추가 합니다.overflow: hidden
transition
panel
max-height
그런 다음 JavaScript를 사용 하여 다양한 화면 크기에서 패널의 높이에 따라 계산된 을 설정하여 콘텐츠를 아래로 슬라이드합니다
.
예시
<style>
.content {
padding: 0 18px;
background-color: white;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
</style>
<script>
var
coll =
document.getElementsByClassName("collapsible");
var i;
for (i = 0; i <
coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.maxHeight){
content.style.maxHeight = null;
} else {
content.style.maxHeight =
content.scrollHeight + "px";
}
});
}
</script>
아이콘 추가
접을 수 있는 콘텐츠가 열려 있는지 닫혀 있는지를 나타내기 위해 각 버튼에 기호를 추가합니다.
예시
.collapsible:after {
content: '\02795'; /* Unicode
character for "plus" sign (+) */
font-size: 13px;
color: white;
float: right;
margin-left: 5px;
}
.active:after {
content: "\2796"; /*
Unicode character for "minus" sign (-) */
}