This user interface was crafted by me and I am seeking the same functionality to be integrated into this design. I want only one menu to be open at a time, rather than having all of them open simultaneously.
Clicking on a button should open or close the current accordion. Additionally, if any other accordion is already open, it should automatically close when you attempt to open another one.
Kindly maintain the same transitioning effect.
var accordians = document.getElementsByClassName("accordion_btn");
for (var i = 0; i < accordians.length; i += 1) {
accordians[i].onclick = function() {
this.classList.toggle('arrowClass');
var content = this.nextElementSibling;
if (content.style.maxHeight) {
// Accordion is open, needs to be closed
content.style.maxHeight = null;
} else {
// Accordion is closed, needs to be open
content.style.maxHeight = content.scrollHeight + "px";
}
}
}
body {
display: grid;
place-items: center;
}
.accordion_container {
background-color: #efefef;
padding: 10px;
width: 500px;
/*height: 400px;*/
overflow: auto;
border-radius: 3px;
/* padding: 10px; */
position: relative;
}
... (the rest of the CSS code remains same)
<div class="accordion_container">
<div class="accordion_body">
<div class="accordion_body_item">
...