JavaScript window.requestAnimationFrame() Method

You are Here:

JavaScript window.requestAnimationFrame() Method

The window.requestAnimationFrame() method tells the browser that you wish to perform an animation and requests that the browser call a specified function to update an animation before the next repaint.

Note: This method takes a callback as an argument to be invoked before the repaint.


HTML Online Editor
<!DOCTYPE html> <html> <body> <button onclick="myStart()">Start</button> <button onclick="myStop()">Stop</button> <p id="point"></p> <script> var x = document.getElementById("point"); var num = 0; var globalID = ""; function myFunction(){ num += 1; x.innerHTML = num; globalID = requestAnimationFrame(myFunction); } function myStart(){ globalID = requestAnimationFrame(myFunction); } function myStop(){ cancelAnimationFrame(globalID); } </script> </body> </html>



Parameter Values

callbackRequiredSpecifies the function to call when it is time to update your animation for the next repaint.


Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author