English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
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‹/›
The numbers in the table specify the first browser version that fully supports the requestAnimationFrame() method:
Method | |||||
requestAnimationFrame() | 24 | 23 | 15 | 6.1 | 10 |
Parameter | Description |
---|---|
callback | Function called when it is necessary to update the animation for the next repaint |
Return Value: | A long integer value (request ID) used to uniquely identify an entry in the callback list |
---|
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