Is it possible to specify a <hue-interpolation-method> for anything other than gradients; specifically: transitions or animations?
.box {
width: 300px;
height: 50px;
}
.box.gradient {
background: linear-gradient(90deg in hsl longer hue, red, blue);
}
.box.transition {
background: red;
transition: 1s all;
}
.box.transition:hover {
background: blue;
}
.box.animation {
animation-name: color;
animation-duration: 2s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
@keyframes color {
0% {
background: red;
}
100% {
background: blue;
}
}
Linear-gradient using hue interpolation:
<div class="box gradient"></div>
<br><br>
Transition (hover) -- how do I get it to use the hue interpolation?
<div class="box transition"></div>
<br><br>
Animation -- how do I get it to use the hue interpolation?
<div class="box animation"></div>
2
Answers
One hacky idea is to keep using the gradient and transition the position:
There is an active discussion to add a
transition-interpolation
property that should cover it, but it’s not yet ready.One other property that does use the
<hue-interpolation-method>
is thecolor-mix()
function, which actually has even better browser support than in gradients.However to animate this is not that easy.
One semi-hackish way is to define
@property
variables that we’ll use as the percentage parameters ofcolor-mix
. This is currently only supported in Chrome though (Safari supports the transition but not the animation, but maybe I messed up somewhere):For browsers that don’t support the
@property
rule and thus animating custom variables, you can create an animation with a lot of keyframes: