requestAnimationFrame
suggest changeSyntax
- window.requestAnimationFrame(callback);
The webkit and moz prefixes are historical. Current browsers provide the unprefixed function. It is a browser API. The callback receives a DOMHighResTimeStamp, and background tabs pause these callbacks.
Parameters
callback: “A parameter specifying a function to call when it’s time to update your animation for the next repaint.” (https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame)
Remarks
requestAnimationFrame schedules work before the next repaint. It does not by itself animate an element, and a CSS transition does not require it.
Animating transform and opacity can stay off the main-thread layout path. Animating layout properties such as top or width forces layout. Neither choice is a guarantee of a smooth frame rate.
| References | URL |
|---|---|
| What is jank? | http://jankfree.org/ |
| High Performance Animations | http://www.html5rocks.com/en/tutorials/speed/high-performance-animations/ |
| R.A.I.L. | https://developers.google.com/web/tools/chrome-devtools/profile/evaluate-performance/rail?hl=en |
| Analyzing Critical Rendering Path | https://developers.google.com/web/fundamentals/performance/critical-rendering-path/analyzing-crp?hl=en |
| Rendering Performance | https://developers.google.com/web/fundamentals/performance/rendering/?hl=en |
| Analyzing Paint Times | https://developers.google.com/web/updates/2013/02/Profiling-Long-Paint-Times-with-DevTools-Continuous-Painting-Mode?hl=en |
| Identifying Paint Bottlenecks | https://developers.google.com/web/fundamentals/performance/rendering/simplify-paint-complexity-and-reduce-paint-areas?hl=en |
Use requestAnimationFrame to fade in element
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents