Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
Animate collapsing of drop down

im trying to replicate this smooth dropdown effect, however can't seem to get it working correctly, this is what I want to replicate, and this is what I have got:

function expand() {
  const elm = document.querySelector('.dropdown__content');

  elm.style.position = 'absolute';
  elm.style.visibility = 'hidden';
  elm.style.display = 'block';

  const height = elm.offsetHeight;

  elm.classList.add('collapsing');
  elm.classList.remove('collapse');

  elm.style.position = null;
  elm.style.visibility = null;
  elm.style.display = null;

  elm.addEventListener('transitionend', function(e) {
      console.log('done', e.propertyName);
      elm.style.height = null;
      elm.classList.remove('collapsing');
      elm.classList.add('show');
  }, false);

  elm.style.height = `${height}px`;
}
.dropdown__content {
  border: 1px solid black;
  border-radius: 20px;
  padding: 20px;
  width: 600px;
  display: block;
}
.collapse:not(.show) {
  display: none;
}
.collapsing {
  height: 0;
  overflow: hidden;
  transition: height 2s ease;
}
<a href="javascript:void(0)" onclick="expand()">Expand</a>
<div class="dropdown__content collapse">
  <p>dsdasdsad</p>
  <p>dsdasdsad</p>
  <p>dsdasdsad</p>
</div>

it's not a smooth animation and it's also not hitting the event listener.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!