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

133
Visualizações
Why does window.requestAnimationFrame run the step function only once?

When opening the following HTML file in a browser, the timestamp is only logged once, why isn't the step function called a bunch of times per second as I would except?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test</title>
</head>
<body>
<script>
    function step(timestamp) { console.log(timestamp) }
    window.requestAnimationFrame(step)
</script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It only ever runs once. For it to repeat we must call requestAnimationFrame inside step for it to continue https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame

Before:

function step(timestamp) {
  console.log(timestamp)
}
window.requestAnimationFrame(step)

After:

let i = 0;

function step(timestamp) {
  console.log(timestamp);
  i++;

  if (i < 10) {
    window.requestAnimationFrame(step);
  }
}
window.requestAnimationFrame(step)

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