How to enable lateral collapse

Viewed 78

I found a really helpful tutorial to help me use javascript to expand and collapse content, but now I can't figure out how to expand the content from left to right instead of vertically. Any ideas?

Alternatively, I'm considering to keep the vertical expansion, but in this case, I can't figure out how to align the flanking buttons in place. Any ideas also on this issue?

var coll = document.getElementsByClassName("collapsible");
var i;

for (i = 0; i < coll.length; i++) {
  coll[i].addEventListener("click", function() {
    this.classList.toggle("active");

    var contents = document.querySelectorAll('div.content')
    contents.forEach((content) => {
      content.style.display = "none"
    })

    var content = this.nextElementSibling;
    if (content.style.display === "block") {
      content.style.display = "none";
    } else {
      content.style.display = "block";
    }
  });
}
.collapsible {
  background-color: #777;
  color: white;
  cursor: pointer;
  padding: 18px;
  width: 100%;
  border: none;
  text-align: left;
  outline: none;
  font-size: 15px;
}

.active,
.collapsible:hover {
  background-color: #555;
}

.collapsible:after {
  content: '\002B';
  color: white;
  font-weight: bold;
  float: right;
  margin-left: 5px;
}

.active:after {
  content: "\2212";
}

.content {
  padding: 0 18px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
  background-color: #f1f1f1;
}
<div class="inner">
  <div class="flex flex-1">
    <buttonait class="collapsible">
      <img src="../../static/consortium/images/people/ESRs/XXX.png" style="object-fit: contain;height:150px;padding-top: 1em"><br>XXX, ESR 1</buttonait>
    <div class="content">
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
    </div>

    <buttonait class="collapsible">
      <img src="../../static/consortium/images/people/ESRs/XXX.png" style="object-fit: contain;height:150px"><br>XXX, ESR 2</buttonait>
    <div class="content">
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
    </div>
  </div>

1 Answers

The key line appears to be in your CSS:

transition: max-height 0.2s ease-out;

Change that to width and you should be fine.

Related