วิธีการ - พับ/หีบเพลง
เรียนรู้วิธีสร้างหีบเพลง (เนื้อหาที่ยุบได้)
หีบเพลง
หีบเพลงมีประโยชน์เมื่อคุณต้องการสลับระหว่างการซ่อนและแสดงเนื้อหาจำนวนมาก:
ความเจ็บปวดนั้นสำคัญ แต่ความเจ็บปวดนั้นเพิ่มขึ้นด้วยกระบวนการอ้วน แต่ฉันให้เวลากับมันเพื่อลดความเจ็บปวดลง เพื่อที่ฉันจะได้ทำงานอย่างเต็มที่และเจ็บปวด เพื่อว่าโดยส่วนใหญ่ พวกเราคนใดคนหนึ่งจะมาทำงานประเภทใดก็ได้ ยกเว้นเพื่อใช้ประโยชน์จากวัตถุประสงค์จากการจ้างงานนั้น
ความเจ็บปวดนั้นสำคัญ แต่ความเจ็บปวดนั้นเพิ่มขึ้นด้วยกระบวนการอ้วน แต่ฉันให้เวลากับมันเพื่อลดความเจ็บปวดลง เพื่อที่ฉันจะได้ทำงานอย่างเต็มที่และเจ็บปวด เพื่อว่าโดยส่วนใหญ่ พวกเราคนใดคนหนึ่งจะมาทำงานประเภทใดก็ได้ ยกเว้นเพื่อใช้ประโยชน์จากวัตถุประสงค์จากการจ้างงานนั้น
ความเจ็บปวดนั้นสำคัญ แต่ความเจ็บปวดนั้นเพิ่มขึ้นด้วยกระบวนการอ้วน แต่ฉันให้เวลากับมันเพื่อลดความเจ็บปวดลง เพื่อที่ฉันจะได้ทำงานอย่างเต็มที่และเจ็บปวด เพื่อว่าโดยส่วนใหญ่ พวกเราคนใดคนหนึ่งจะมาทำงานประเภทใดก็ได้ ยกเว้นเพื่อใช้ประโยชน์จากวัตถุประสงค์จากการจ้างงานนั้น
สร้างหีบเพลง
ขั้นตอนที่ 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) เพิ่ม JavaScript:
ตัวอย่าง
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: 0
และoverflow: hidden
a transition
สำหรับคุณสมบัติความสูงสูงสุด ในpanel
ชั้นเรียน
จากนั้น ใช้ JavaScript เพื่อเลื่อนเนื้อหาลงโดยการตั้งค่า การคำนวณ
max-height
ขึ้นอยู่กับความสูงของแผงในขนาดหน้าจอต่างๆ:
ตัวอย่าง
<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 (-) */
}