Adding and subtracting animations
This example demonstrates that animation values can be added, subtracted, multiplied and divided with each other to create more complex animations. The standard JavaScript operators like +
and -
may be used.
tsx
import {AbsoluteFill ,interpolate ,spring ,useCurrentFrame ,useVideoConfig ,} from "remotion";export constTwoPushes :React .FC = () => {constframe =useCurrentFrame ();const {fps } =useVideoConfig ();constscalePush1 =spring ({fps ,frame ,config : {damping : 200,},});constscalePush2 =spring ({fps ,frame :frame - 30,config : {damping : 200,},});constscalePush3 =spring ({fps ,frame :frame - 60,config : {damping : 200,},});constscale =scalePush1 +scalePush2 +scalePush3 ;constleft =interpolate (scalePush1 , [0, 1], [0, 80]) +interpolate (scalePush2 , [0, 1], [0, 80]) +interpolate (scalePush3 , [0, 1], [0, 80]);return (<AbsoluteFill style ={{justifyContent : "center",padding : 50,backgroundColor : "white",}}><div style ={{height : 100,width : 100,backgroundColor : "#4290f5",borderRadius : 40,transform : `scale(${scale }) translateX(${left }px)`,}}/></AbsoluteFill >);};
tsx
import {AbsoluteFill ,interpolate ,spring ,useCurrentFrame ,useVideoConfig ,} from "remotion";export constTwoPushes :React .FC = () => {constframe =useCurrentFrame ();const {fps } =useVideoConfig ();constscalePush1 =spring ({fps ,frame ,config : {damping : 200,},});constscalePush2 =spring ({fps ,frame :frame - 30,config : {damping : 200,},});constscalePush3 =spring ({fps ,frame :frame - 60,config : {damping : 200,},});constscale =scalePush1 +scalePush2 +scalePush3 ;constleft =interpolate (scalePush1 , [0, 1], [0, 80]) +interpolate (scalePush2 , [0, 1], [0, 80]) +interpolate (scalePush3 , [0, 1], [0, 80]);return (<AbsoluteFill style ={{justifyContent : "center",padding : 50,backgroundColor : "white",}}><div style ={{height : 100,width : 100,backgroundColor : "#4290f5",borderRadius : 40,transform : `scale(${scale }) translateX(${left }px)`,}}/></AbsoluteFill >);};