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