Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda