interpolateStyles()
Part of the @remotion/animation-utils
package.
This function provides a convenient way to interpolate styles based on a specified range of values, allowing for smooth animations between different styles.
Example
tsx
import {interpolateStyles ,makeTransform ,translateY ,} from "@remotion/animation-utils";constMyComponent :React .FC = () => {constanimatedStyles =interpolateStyles (15,[0, 30, 60],[{opacity : 0,transform :makeTransform ([translateY (-50)]) },{opacity : 1,transform :makeTransform ([translateY (0)]) },{opacity : 0,transform :makeTransform ([translateY (50)]) },],);return <div style ={animatedStyles } />;};
tsx
import {interpolateStyles ,makeTransform ,translateY ,} from "@remotion/animation-utils";constMyComponent :React .FC = () => {constanimatedStyles =interpolateStyles (15,[0, 30, 60],[{opacity : 0,transform :makeTransform ([translateY (-50)]) },{opacity : 1,transform :makeTransform ([translateY (0)]) },{opacity : 0,transform :makeTransform ([translateY (50)]) },],);return <div style ={animatedStyles } />;};
API
A function that takes 3-4 arguments:
- The input value.
- The range of values that you expect the input to assume.
- The range of output styles that you want the input to map to.
- Options object, same as the options of
interpolate()
(optional)
Return value
- A style object representing the interpolated styles based on the current frame.
Usage Notes
Ensure that the
inputRange
andoutputStylesRange
arrays contain at least two values to facilitate interpolation between styles.The
outputStylesRange
array must have the same number of elements asinputRange
. Each style inoutputStylesRange
corresponds to a specific value in the input range.