English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Window requestAnimationFrame() method

JavaScript Window Object

requestAnimationFrame()The method tells the browser that you want to perform an animation and requests that the browser calls the specified function to update the animation before the next repaint.

This method takes a callback as a parameter to be called before the next repaint.

Syntax:

window.requestAnimationFrame(callback)
var start = null;
var element = document.getElementById('anim');
function step(timestamp) {
  if (!start) start = timestamp;
  var progress = timestamp - start;
  element.style.transform = 'translateX(' + Math.min(progress / 10, 400) + 'px)';
  if (progress < 20000) {}}
     window.requestAnimationFrame(step);
  }
}
window.requestAnimationFrame(step);
Test See‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the requestAnimationFrame() method:

Method
requestAnimationFrame()2423156.110

Parameter Value

ParameterDescription
callbackFunction called when it is necessary to update the animation for the next repaint

Technical Details

Return Value:A long integer value (request ID) used to uniquely identify an entry in the callback list

Related References

CSS Tutorial:CSS animation

CSS Reference:CSS animation properties

CSS Reference:CSS animation-delay property

CSS Reference:CSS animation direction property

CSS Reference:CSS animation duration property

CSS Reference:CSS animation-fill-mode property

CSS Reference:CSS animation-iteration-count property

CSS Reference:CSS animation-name property

CSS Reference:CSS animation-play-state property

CSS Reference:CSS animation-timing-function property

JavaScript Window Object