measureSpring()
基于 spring() 配置和帧率,返回一个弹簧动画稳定所需的时间。
🌐 Based on a spring() configuration and the frame rate, return how long it takes for a spring animation to settle.
import {measureSpring , SpringConfig } from 'remotion';
const config : Partial <SpringConfig > = {
damping : 200,
};
measureSpring ({
fps : 30,
config : {
damping : 200,
},
}); // => 23理论上,弹簧动画永远不会结束。弹簧里总会有微小的能量残留,导致微小的运动。相反,我们设置一个阈值来定义弹簧动画何时被认为完成。
参数
🌐 Arguments
具有这些键的对象:
🌐 An object with these keys:
fps
弹簧动画所基于的帧率。
🌐 The frame rate on which the spring animation is based on.
threshold?
定义何时应视动画为完成。默认值:0.005。0.01 意味着当动画始终保持在 to 值的1%范围内时被视为完成。例如,一个从0到1的动画在结束点之后,如果值始终保持在[0.99, 1.01]范围内,则被视为完成。
🌐 Defines when the animation should be considered finished. Default: 0.005. 0.01 means that the animation is finished when it always stays within 1% of the to value. For example an animation that goes from 0 to 1 is considered finished when the value never leaves the range [0.99, 1.01] after the end point.
较低的数值意味着弹簧持续时间更长,较高的数值会导致弹簧持续时间更短。
🌐 Lower values mean the spring duration is longer, higher values result in the spring duration being shorter.
config?
你传递给 spring() 的弹簧配置。
🌐 The spring configuration that you pass to spring().
from?
动画的初始值。默认值:0。
🌐 The initial value of the animation. Default: 0.
to?
动画的最终值。默认值:1。请注意,根据参数的不同,弹簧动画可能会在最终回到目标值之前稍微超过目标值。
🌐 The end value of the animation. Default: 1. Note that depending on the parameters, spring animations may overshoot the target a bit, before they bounce back to their final target.
兼容性
🌐 Compatibility
| Browsers | Servers | Environments | |||||||
|---|---|---|---|---|---|---|---|---|---|
Chrome | Firefox | Safari | Node.js | Bun | Serverless Functions | ||||
另请参阅
🌐 See also