Animation math
You can add, subtract and multiply animation values to create more complex animations.
Consider the following example:
Enter and exittsx
import {spring ,useCurrentFrame ,useVideoConfig } from "remotion";constframe =useCurrentFrame ();const {fps ,durationInFrames } =useVideoConfig ();constenter =spring ({fps ,frame ,config : {damping : 200,},});constexit =spring ({fps ,config : {damping : 200,},durationInFrames : 20,delay :durationInFrames - 20,frame ,});constscale =enter -exit ;
Enter and exittsx
import {spring ,useCurrentFrame ,useVideoConfig } from "remotion";constframe =useCurrentFrame ();const {fps ,durationInFrames } =useVideoConfig ();constenter =spring ({fps ,frame ,config : {damping : 200,},});constexit =spring ({fps ,config : {damping : 200,},durationInFrames : 20,delay :durationInFrames - 20,frame ,});constscale =enter -exit ;
- At the beginning of the animation, the value of
enter
is0
, it goes to1
over the course of the animation. - Before the sequence ends, we create an
exit
animation that goes from0
to1
. - Subtracting the
exit
animation from theenter
animation gives us the overall state of the animation which we use to animatescale
.
Full snippettsx
importReact from "react";import {AbsoluteFill ,spring ,useCurrentFrame ,useVideoConfig ,} from "remotion";export constAnimationMath :React .FC = () => {constframe =useCurrentFrame ();const {fps ,durationInFrames } =useVideoConfig ();constenter =spring ({fps ,frame ,config : {damping : 200,},});constexit =spring ({fps ,config : {damping : 200,},durationInFrames : 20,delay :durationInFrames - 20,frame ,});constscale =enter -exit ;return (<AbsoluteFill style ={{justifyContent : "center",alignItems : "center",backgroundColor : "white",}}><div style ={{height : 100,width : 100,backgroundColor : "#4290f5",borderRadius : 20,transform : `scale(${scale })`,justifyContent : "center",alignItems : "center",display : "flex",fontSize : 50,color : "white",}}>{frame }</div ></AbsoluteFill >);};
Full snippettsx
importReact from "react";import {AbsoluteFill ,spring ,useCurrentFrame ,useVideoConfig ,} from "remotion";export constAnimationMath :React .FC = () => {constframe =useCurrentFrame ();const {fps ,durationInFrames } =useVideoConfig ();constenter =spring ({fps ,frame ,config : {damping : 200,},});constexit =spring ({fps ,config : {damping : 200,},durationInFrames : 20,delay :durationInFrames - 20,frame ,});constscale =enter -exit ;return (<AbsoluteFill style ={{justifyContent : "center",alignItems : "center",backgroundColor : "white",}}><div style ={{height : 100,width : 100,backgroundColor : "#4290f5",borderRadius : 20,transform : `scale(${scale })`,justifyContent : "center",alignItems : "center",display : "flex",fontSize : 50,color : "white",}}>{frame }</div ></AbsoluteFill >);};