Page 46 - CSS
P. 46
Note: The transition property can animate changes between any two numerical values,
regardless of unit. It can also transition between units, such as 100px to 50vh. However, it cannot
transition between a number and a default or automatic value, such as transitioning an element's
height from 100px to auto.
Increasing Animation Performance Using the `will-change` Attribute
When creating animations and other GPU-heavy actions, it's important to understand the will-
change attribute.
Both CSS keyframes and the transition property use GPU acceleration. Performance is increased
by offloading calculations to the device's GPU. This is done by creating paint layers (parts of the
page that are individually rendered) that are offloaded to the GPU to be calculated. The will-
change property tells the browser what will animate, allowing the browser to create smaller paint
areas, thus increasing performance.
The will-change property accepts a comma-separated list of properties to be animated. For
example, if you plan on transforming an object and changing its opacity, you would specify:
.Example{
...
will-change: transform, opacity;
}
Note: Use will-change sparingly. Setting will-change for every element on a page can cause
performance problems, as the browser may attempt to create paint layers for every element,
significantly increasing the amount of processing done by the GPU.
Animations with keyframes
For multi-stage CSS animations, you can create CSS @keyframes. Keyframes allow you to define
multiple animation points, called a keyframe, to define more complex animations.
Basic Example
In this example, we'll make a basic background animation that cycles between all colors.
@keyframes rainbow-background {
0% { background-color: #ff0000; }
8.333% { background-color: #ff8000; }
16.667% { background-color: #ffff00; }
25.000% { background-color: #80ff00; }
33.333% { background-color: #00ff00; }
41.667% { background-color: #00ff80; }
50.000% { background-color: #00ffff; }
58.333% { background-color: #0080ff; }
66.667% { background-color: #0000ff; }
75.000% { background-color: #8000ff; }
83.333% { background-color: #ff00ff; }
https://riptutorial.com/ 24

