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

224
Vistas
How to align CSS animation-delay in with NodeJS delay?

How do I add a preloader when my setTimeout is in NodeJS, below is the code to call the api and set a delay for 10s:

function delay(s){
    return new Promise(resolve => setTimeout(resolve,s));
}


async function getXml(){
let ans;
await delay(10000)
const {data} = await axios.get('https://gist.githubusercontent.com/SwayamShah97/a3619c5828ac8ed8085c4ae295a855d9/raw/e4e372552e042bd8bd9e8ab87da93eb030114f86/people.xml');
xml2js.parseString(data, (err, result) => {
    if(err) {
        throw err;
    }
    ans = result
    
});

I have tried to add the loader using frontend js like this:

window.addEventListener("load", function () {
    const loader = document.querySelector(".loader");
    loader.className += " hidden"; // class "loader hidden"
});

HTML:

<div class="loader">
    <img src="/public/images/coffee-loading.gif" alt="Loading..." />
</div>

CSS:

.loader.hidden {
    animation: fadeOut 10s;
    animation-fill-mode: forwards;
}

@keyframes fadeOut {
    100% {
        opacity: 0;
        visibility: hidden;
    }
} 

How it works is, it waits 10s as it should due to the setTimeout, and then shows the preloader for additional 10s instead of aligning with the delay.

How can I achieve this functionality?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

animation-delay: 10s;

I should note that this is pretty bad in terms of user experience unless you plan on reducing those timers.

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