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

187
Visualizações
Javascript per second calculation

I am currently wracking my brain to work out what should probably be a relatively simple per second calculation. I have a loading bar increase and at the end of that, it adds 1 to the total. The loading bar consists of:

wId = setInterval(worker_identify_call, wIdSpeed);

and

function worker_identify_call(){
    worker_identify_amount++;
    wElem.style.width = worker_identify_amount + '%';
}

wIdSpeed = 250.

I am trying to calculate how long, in seconds, it will take to reach the top of the loading bar (100%).

I currently have ((1000/wIdSpeed).toFixed(2)) but that just calculates how long a cycle of setInterval takes.

CodePen with example here.

Any help is appreciated!

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

0

If you want to recalculate after every cycle you have to move workerString(); to inside the function that loops.

As for the math, you need to get the remaining (100 - worker_identify_amount) and check how many things it's adding per second and figure out the result from that.

about 4 years ago · Juan Pablo Isaza Relatório

0

I'm in idiot. For anyone that wants to find this in the future, it would be:

(((wIdSpeed/1000)*100).toFixed(2));

Where wIdSpeed is the speed of your interval.

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