Parameter | Details |
---|---|
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) |
When it comes to animating DOM elements fluidly, we are limited to the following CSS transitions:
transform: translate (npx, npx);
transform: scale(n)
;transform: rotate(ndeg);
opacity: 0;
However, using these is no guarantee that your animations will be fluid, because it causes the browser to start new paint
cycles, regardless of what else is going on. Basically, paint
are made inefficiently and your animation looks "janky" because the frames per second (FPS) suffers.
To guarantee smooth-as-possible DOM animations, requestAnimationFrame must be used in conjunction with the above CSS transitions.
The reason this works, is because the requestAnimationFrame
API lets the browser know that you want an animation to happen at the next paint
cycle, as opposed to interrupting what's going on to force a new paint cycle in when a non-RAF animation is called.
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 |