Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
Can we use a callback function to delay the execution of display="none"?

Hello all
I want to create an animation for a dropdown using css and javascript. But when the display is set to none, the animations don't work maybe because display property can't be animated. But if I delay the display property, it gives animation enough time to load. So is there any possible method to delay the same display property through callback function? Here is my code:

function myfun() {
  let dis = document.getElementsByClassName("litems")[0];
  if (dis.style.display == "none") {
    dis.style.display = "block";
    dis.style.animation = "up 2s ease-in 1"
  } else {
    dis.style.animation = "down 2s ease-in 1";
    setTimeout(() => {
      dis.style.display = "none";
    }, 2000)
  }
}
.list ul {
  background: orchid;
  position: absolute;
  display: block;
}

@keyframes up {
  0% {
    top: 0px;
    background: white;
  }
  100% {
    top: 400px;
    background: orange;
  }
}

@keyframes down {
  0% {
    top: 400px;
    background: orange;
  }
  100% {
    top: 0px;
    background: white;
  }
}
  <button onclick="myfun()">Click it to toggle</button>
  <div class="list">
    <ul class="litems">
      <li>Item 1</li>
      <li>Item 2</li>
      <li>Item 3</li>
      <li>Item 4</li>
    </ul>
  </div>
</body>

Thank you very much.

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda