Some Examples » 24. Colors: Interpolation
24. Colors: Interpolation
Here, the useTransform()
hook interpolates between three colors.
Code component
Here, we have an x
Motion value that is passed to the horizontally draggable circle and which transforms the backgroundColor
between “#a0d”, "rgba(0,0,0,0)"
(that’s black; with zero transparency), and “#0bf”.
Code overrides
The useMotionValue()
hook only works inside functions, so when sharing a Motion value between overrides, we use motionValue()
instead.
We also have an x
Motion value that we pass to the horizontally draggable circle:
… and which is used in a second override to interpolate the backgroundColor
between “#a0d”, "rgba(0,0,0,0)"
(that’s black; with zero transparency), and “#0bf”.