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

223
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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