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

94
Vistas
How to add animation?

How will I add fadeout animation in this javascript code?

document.getElementById("mt-alerts").style.display="block";
setTimeout(function(){
    document.getElementById("mt-alerts").style.display="none";
}, 2000);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You should make classses for every animations, and the JS should change only the classes of the items. You can with this method, make your own animatsions.

const alertMsg = document.getElementById("mt-alerts");
const hide = document.getElementById("hide");
const red = document.getElementById("red");

hide.addEventListener("click", ()=> alertMsg.classList.toggle("hidden"));
red.addEventListener("click", ()=> alertMsg.classList.toggle("red"));
#mt-alerts {
  opacity: 1;
  transition: all 0.5s linear;
  color: black;
}

.hidden {
  opacity: 0!important;
}

.red {
  color: red!important;
}
<div id="mt-alerts">My Alert</div>
<button id="hide">Hide/show</button>
<button id="red">Make it red</button>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Instead of using display, you need to start with opacity for this.

The idea is simply decrease the opacity of your element until it reaches the 0, then set its display as none. To fade in you can repeat the idea in reverse.

function js_fadeOut(targetID, intervalMs, fadeWeight) {

    var fadeTarget = document.getElementById(targetID);
    
    var fadeEffect = setInterval(function () {
        if (!fadeTarget.style.opacity) {
            fadeTarget.style.opacity = 1;
        }
        if (fadeTarget.style.opacity > 0) {
            fadeTarget.style.opacity -= fadeWeight;
        } else {
            fadeTarget.style.display = "none";
            clearInterval(fadeEffect);
        }
    }, intervalMs*fadeWeight);
}
<div id='target' style='padding:8px; background:lightblue;' onclick='js_fadeOut("target", 200, 0.1)'>Click to fadeOut</div>

about 4 years ago · Juan Pablo Isaza Denunciar
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