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

155
Visualizações
Get the loading progress in JavaScript

So I'm thinking about making a gravatar link getter and I would like to add a loading screen but I don't know how to get loading progress with JavaScript when loading HTML and CSS assets

let loadingpercent = percent();

function LoadProj()
{
  document.write("Hold On, your request is loading.<br> " + loadingpercent);
}

function percent()
{
    //Code Goes here
    return NaN;
}
<input type="button" onClick="LoadProj()" value="LoadMe">

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can store the percent in a variable and the interval at which the progress should increment in another (in ms).

Then, in your LoadProj function, increment the percent and set the innerHTML of the body to the right value. Check if the percent is not 100. If it is not, we can use setTimeout to call LoadProj again with a delay, in our case, loadInterval. If it is, you know that it is finished loading, and you can handle it accordingly.

var percent = 0;
var loadInterval = 100;

function LoadProj() {
  percent++;
  document.body.innerHTML = "Hold On, your request is loading. " + percent;
  if (percent != 100) {
    setTimeout(LoadProj, loadInterval)
  }else{
    //Finished loading! Your code here...
    console.log('Finished loading!')
  }
}
<input type="button" onClick="LoadProj()" value="LoadMe">

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