缓动
Easing 模块实现了常见的缓动函数。您可以将其与 interpolate() API 一起使用。
您可以在 http://easings.net/ 找到一些常见缓动函数的可视化。
预定义动画
Easing 模块通过以下方法提供了几种预定义动画:
标准函数
提供了三个标准缓动函数:
poly 函数可用于实现四次方、五次方和其他更高次方函数。
附加函数
通过以下方法提供了额外的数学函数:
以下辅助函数用于修改其他缓动函数。
示例
tsximport {Easing ,interpolate } from "remotion";constMyVideo :React .FC = () => {constframe =useCurrentFrame ();constinterpolated =interpolate (frame , [0, 100], [0, 1], {easing :Easing .bezier (0.8, 0.22, 0.96, 0.65),extrapolateLeft : "clamp",extrapolateRight : "clamp",});return (<AbsoluteFill style ={{transform : `scale(${interpolated })`,backgroundColor : "red",}}/>);};
tsximport {Easing ,interpolate } from "remotion";constMyVideo :React .FC = () => {constframe =useCurrentFrame ();constinterpolated =interpolate (frame , [0, 100], [0, 1], {easing :Easing .bezier (0.8, 0.22, 0.96, 0.65),extrapolateLeft : "clamp",extrapolateRight : "clamp",});return (<AbsoluteFill style ={{transform : `scale(${interpolated })`,backgroundColor : "red",}}/>);};
参考
方法
step0
jsxstatic step0(n): number
jsxstatic step0(n): number
一个阶跃函数,对于任何正值的 n 返回 1。
step1
jsxstatic step1(n): number
jsxstatic step1(n): number
一个阶跃函数,如果 n 大于或等于 1,则返回 1。
linear
jsxstatic linear(t): number
jsxstatic linear(t): number
一个线性函数,f(t) = t。位置与经过的时间一一对应。
http://cubic-bezier.com/#0,0,1,1
ease
jsxstatic ease(t): number
jsxstatic ease(t): number
一种基本的惯性交互,类似于物体缓慢加速到速度。
http://cubic-bezier.com/#.42,0,1,1
quad
jsxstatic quad(t): number
jsxstatic quad(t): number
一个二次函数,f(t) = t * t。位置等于经过的时间的平方。
http://easings.net/#easeInQuad
cubic
jsxstatic cubic(t): number
jsxstatic cubic(t): number
一个三次函数,f(t) = t * t * t。位置等于经过的时间的立方。
http://easings.net/#easeInCubic
poly()
jsxstatic poly(n): (t) => number
jsxstatic poly(n): (t) => number
一个幂函数。位置等于经过的时间的N次幂。
n = 4: http://easings.net/#easeInQuart n = 5: http://easings.net/#easeInQuint
sin
jsxstatic sin(t): number
jsxstatic sin(t): number
一个正弦函数。
http://easings.net/#easeInSine
circle
jsxstatic circle(t): number
jsxstatic circle(t): number
一个圆形函数。
http://easings.net/#easeInCirc
exp
jsxstatic exp(t): number
jsxstatic exp(t): number
一个指数函数。
http://easings.net/#easeInExpo
elastic()
jsxstatic elastic(bounciness): (t) => number
jsxstatic elastic(bounciness): (t) => number
一种基本的弹性交互,类似于弹簧来回振荡。
默认的弹性为1,会稍微超过一点。弹性为0时完全不会超过,弹性为N > 1时会超过大约N次。
http://easings.net/#easeInElastic
back()
jsxstatic back(s): (t) => number
jsxstatic back(s): (t) => number
与 Animated.parallel() 结合使用,创建一个基本效果,对象在动画开始时稍微向后动画。
bounce
jsxstatic bounce(t): number
jsxstatic bounce(t): number
提供一个基本的弹跳效果。
http://easings.net/#easeInBounce
查看下面如何使用的示例
jsxinterpolate(0.5, [0, 1], [0, 1], {easing: Easing.bounce,});
jsxinterpolate(0.5, [0, 1], [0, 1], {easing: Easing.bounce,});
bezier()
jsxstatic bezier(x1, y1, x2, y2) => (t): number
jsxstatic bezier(x1, y1, x2, y2) => (t): number
提供一个三次贝塞尔曲线,相当于 CSS 过渡的 transition-timing-function。
一个有用的工具,用于可视化三次贝塞尔曲线,可以在 http://cubic-bezier.com/ 找到。
jsxinterpolate(0.5, [0, 1], [0, 1], {easing: Easing.bezier(0.5, 0.01, 0.5, 1),});
jsxinterpolate(0.5, [0, 1], [0, 1], {easing: Easing.bezier(0.5, 0.01, 0.5, 1),});
in(easing)
jsxstatic in(easing: (t: number) => number): (t: number) => number;
jsxstatic in(easing: (t: number) => number): (t: number) => number;
运行一个缓动函数,向前运行。
jsx{easing: Easing.in(Easing.ease);}
jsx{easing: Easing.in(Easing.ease);}
out()
jsxstatic out(easing: (t: number) => number): (t: number) => number;
jsxstatic out(easing: (t: number) => number): (t: number) => number;
运行一个缓动函数,向后运行。
jsx{easing: Easing.out(Easing.ease);}
jsx{easing: Easing.out(Easing.ease);}
inOut()
jsxstatic inOut(easing: (t: number) => number): (t: number) => number;
jsxstatic inOut(easing: (t: number) => number): (t: number) => number;
jsx{easing: Easing.inOut(Easing.ease);}
jsx{easing: Easing.inOut(Easing.ease);}
使任何缓动函数对称。缓动函数将在持续时间的前半部分向前运行,然后在剩余的持续时间内向后运行。
Credits
Easing API与React Native中的API完全相同,文档已复制过来。感谢他们提供了这个出色的API。
