Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!