Performance: Saturate and desaturate
This affects the CSS paint time and rendering speed by changing color saturation dynamically.
$base-color: #3498db; $desat-color: desaturate($base-color, 50%); $sat-color: saturate($base-color, 30%); .element { background-color: $desat-color; color: $sat-color; }
$color: #3498db; .element { background-color: desaturate($color, 50%); color: saturate($color, 30%); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Dynamic saturate/desaturate on many elements | Low | 0 | High (multiple paints) | [X] Bad |
| Precomputed saturate/desaturate colors in variables | Low | 0 | Low (single paint) | [OK] Good |
saturate() function do to a color in Sass?saturate() function increases the intensity of the color's saturation, making it look more vivid.desaturate() function takes two arguments separated by a comma: the color and the percentage to reduce saturation.desaturate(#ff0000, 20%) is correct.$color: #6699cc; $new-color: saturate($color, 30%);
saturate($color, 30%) increases its saturation, making it more vivid.$color: #00ff00; $new-color: desaturate $color 50%;
$color and 50%.#00ff00 is valid, and the percentage is correctly given as 50%. The function name desaturate is correct for reducing saturation.#ff6600 but looks less intense on hover by reducing saturation by 40%. Which Sass code correctly achieves this?desaturate($base-color, 40%) is needed.Pass the test and this pattern moves unknown