Here, requestAnimationFrame() came into the picture. Basically, requestAnimationFrame() method easily syncs in with your browser timings and generate a call to perform the specific animation before the actual loading of the screen. Further, it also slows down its process when the animation is actually not in the use thus saving resources.
window.requestAnimationFrame( callback );
Parameter: This method accepts single parameter as mentioned above and described below:
- callback: Unless you want the animation to stop, you should write the callback function so that it calls itself so that a request to the next frame is made. Callback function takes timestamp or simply a time value at which it should start executing.
Return Values: This method returns a non zero long integer value that acts as a unique identity for the animation entry in callback function.
Below examples illustrate the requestAnimationFrame() method in Web API:
Supported Browsers: The browsers supported by Window.requestAnimationFrame() Method are listed below:
- Google Chrome 23.0
- Internet Explorer 10.0
- Firefox 11.0
- Opera 10.0
- Safari 6.1