动画数学
你可以对动画数值进行加法、减法和乘法运算,以创建更复杂的动画。 请考虑以下示例:
🌐 You can add, subtract and multiply animation values to create more complex animations.
Consider the following example:
Enter and exitimport {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的值是0,在动画过程中,它会变为1。 - 在序列结束之前,我们创建一个从
0到1的exit动画。 - 从
enter动画中减去exit动画可以得到动画的整体状态,我们用它来动画化scale。
Full snippetimportReact 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 > ); };