Skip to content

Commit 6b622bd

Browse files
committed
add js to accordion
1 parent 218d616 commit 6b622bd

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

css/accordion.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
.panel {
1717
padding: 0 18px;
1818
background-color: white;
19-
display: none;
19+
max-height: 0;
2020
overflow: hidden;
21+
transition: max-height 0.2s ease-out;
2122
}

js/accordion.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var acc = document.getElementsByClassName("accordion-jkj");
2+
var i;
3+
4+
for (i = 0; i < acc.length; i++) {
5+
acc[i].addEventListener("click", function() {
6+
this.classList.toggle("active");
7+
var panel = this.nextElementSibling;
8+
if (panel.style.maxHeight) {
9+
panel.style.maxHeight = null;
10+
} else {
11+
panel.style.maxHeight = panel.scrollHeight + "px";
12+
}
13+
});
14+
}

pages/accordion.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<link rel="stylesheet" href="../css/style.css" />
2323
<link rel="stylesheet" href="../css/accordion.css" />
2424
<link rel="stylesheet" href="../css/cardcolor.css" />
25-
<link rel="stylesheet" href="../css/assets/magic.css" />
25+
<link rel="stylesheet" href="../css/assets/magic.css" />
2626
</head>
2727

2828
<body>
@@ -60,17 +60,17 @@ <h3>Add your different Accordion</h3>
6060

6161
<button class="accordion-jkj">Section 1</button>
6262
<div class="panel">
63-
<p>Lorem ipsum...</p>
63+
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Maiores voluptates doloribus asperiores repellat quaerat illum ad enim minima eaque est!</p>
6464
</div>
6565

6666
<button class="accordion-jkj">Section 2</button>
6767
<div class="panel">
68-
<p>Lorem ipsum...</p>
68+
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Voluptate fugit voluptatibus accusamus non inventore laborum aliquam sint! Maxime, saepe repellendus!</p>
6969
</div>
7070

7171
<button class="accordion-jkj">Section 3</button>
7272
<div class="panel">
73-
<p>Lorem ipsum...</p>
73+
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus nulla laborum suscipit iusto obcaecati ipsam soluta, in sit iste temporibus?</p>
7474
</div>
7575

7676
</div>
@@ -103,5 +103,6 @@ <h2>
103103
<p>made with 💛 by, <br /><strong>CS CHAPTER AJCESB</strong></p>
104104
</footer>
105105
<script src="../js/index.js"></script>
106+
<script src="../js/accordion.js"></script>
106107
</body>
107108
</html>

0 commit comments

Comments
 (0)