interactivity-best-practices
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseInteractivity Best Practices
交互性最佳实践
Use these guidelines when creating or reviewing Remotion animations, especially if the animation should be editable in Remotion Studio Visual Mode.
在创建或审查 Remotion 动画时使用这些准则,尤其是在动画应可于 Remotion Studio Visual Mode 中编辑时。
Prefer interpolate()
over standalone spring()
interpolate()spring()优先使用 interpolate()
,而非独立的 spring()
interpolate()spring()Prefer for most animation values.
interpolate()- It is easier for humans and agents to reason about.
- Bezier easings are familiar from CSS and can express snappy or jumpy motion.
- Studio Visual Mode can edit keyframes.
interpolate()
When an animation should feel like a spring, keep the editable value in and pass as the easing function.
interpolate()Easing.spring()Prefer:
tsx
style={{
scale: interpolate(frame, [0, 30], [0, 1], {
easing: Easing.spring({
damping: 200,
}),
}),
}}❌ Avoid using as a separate driver when the same motion can be expressed as easing:
spring()interpolate()tsx
const scale = spring({
frame,
fps,
config: {
damping: 200,
},
});
style={{
scale,
}}Easing.spring()dampingmassstiffnessovershootClampingframefpsfromtodelayreversedurationInFramesdurationRestThresholdUse standalone only when the animation specifically needs a frame-driven physical spring simulation that cannot be represented as an easing on .
spring()interpolate()对于大多数动画值,优先使用 。
interpolate()- 它更便于人类和 Agent 理解。
- Bezier 缓动函数与 CSS 中的写法一致,能够表现灵敏或跳跃的运动。
- Studio Visual Mode 可以编辑 关键帧。
interpolate()
如果动画需要呈现弹簧效果,请将可编辑值保留在 中,并把 作为缓动函数传入。
interpolate()Easing.spring()推荐:
tsx
style={{
scale: interpolate(frame, [0, 30], [0, 1], {
easing: Easing.spring({
damping: 200,
}),
}),
}}❌ 当相同的运动效果可以通过 缓动来表达时,避免将 作为单独的驱动函数:
interpolate()spring()tsx
const scale = spring({
frame,
fps,
config: {
damping: 200,
},
});
style={{
scale,
}}Easing.spring()dampingmassstiffnessovershootClampingframefpsfromtodelayreversedurationInFramesdurationRestThreshold仅当动画明确需要由帧驱动的物理弹簧模拟,且无法通过 缓动来表达时,才使用独立的 。
interpolate()spring()Prefer individual CSS transform properties
优先使用单独的 CSS transform 属性
Use individual CSS transform properties such as , , and instead of composing a string.
scalerotatetranslatetransformPrefer:
tsx
style={{
scale: interpolate(frame, [0, 100], [0, 2]),
}}❌ Avoid:
tsx
style={{
transform: `scale(${interpolate(frame, [0, 100], [0, 2])})`,
}}Individual transform properties are editable in Studio Visual Mode. Values hidden inside a string are not.
transform使用 、 和 等单独的 CSS transform 属性,不要拼接 字符串。
scalerotatetranslatetransform推荐:
tsx
style={{
scale: interpolate(frame, [0, 100], [0, 2]),
}}❌ 避免:
tsx
style={{
transform: `scale(${interpolate(frame, [0, 100], [0, 2])})`,
}}单独的 transform 属性可以在 Studio Visual Mode 中编辑,而隐藏在 字符串中的值无法编辑。
transformKeep editable values inline
保持可编辑值内联
Put the interpolation directly in the JSX style object when the value should be visually editable.
Prefer:
tsx
style={{
scale: interpolate(frame, [0, 100], [0, 2]),
}}❌ Avoid:
tsx
const scale = interpolate(frame, [0, 100], [0, 2]);
style={{
scale,
}}Inline computations and literal values let Studio Visual Mode discover and edit the keyframes and props.
This also applies to effect parameters. Keep editable effect values inline in the effect call.
Prefer:
tsx
effects={[
radialProgressiveBlur({
center: [0.5, 0.5],
point1: [0.86, 0.36],
point2: [0.68, 0.84],
}),
]}❌ Avoid hiding editable values behind constants:
tsx
const center = [0.5, 0.5] as const;
effects={[
radialProgressiveBlur({
center,
}),
]}当某个值应支持可视化编辑时,将插值计算直接放在 JSX style 对象中。
推荐:
tsx
style={{
scale: interpolate(frame, [0, 100], [0, 2]),
}}❌ 避免:
tsx
const scale = interpolate(frame, [0, 100], [0, 2]);
style={{
scale,
}}内联计算和字面量能让 Studio Visual Mode 发现并编辑关键帧和 props。
这同样适用于 effect 参数。请将可编辑的 effect 值内联放在 effect 调用中。
推荐:
tsx
effects={[
radialProgressiveBlur({
center: [0.5, 0.5],
point1: [0.86, 0.36],
point2: [0.68, 0.84],
}),
]}❌ 避免通过常量隐藏可编辑值:
tsx
const center = [0.5, 0.5] as const;
effects={[
radialProgressiveBlur({
center,
}),
]}Keep effects unconditional
保持 effects 无条件执行
When using the prop, keep the effect array shape unconditional. Studio Visual Mode cannot reliably edit an effect that only exists behind a conditional expression.
effectsPrefer rendering separate elements when one version should have effects and another should not:
tsx
<CanvasImage src={src} width={1280} height={720} />
<CanvasImage
src={src}
width={1280}
height={720}
effects={[
blur({
radius: interpolate(frame, [0, 100], [0, 40]),
}),
]}
/>❌ Avoid conditionally including an effect:
tsx
<CanvasImage
src={src}
width={1280}
height={720}
effects={enabled ? [blur({radius: 40})] : []}
/>Keep editable effect parameters inline inside the unconditional effect call. Do not pass variables for editable values such as coordinates, colors, numeric controls, or interpolations.
使用 prop 时,保持 effect 数组的结构无条件执行。Studio Visual Mode 无法可靠地编辑仅在条件表达式后存在的 effect。
effects如果一个版本应有 effect,而另一个版本不应有,请渲染单独的元素:
tsx
<CanvasImage src={src} width={1280} height={720} />
<CanvasImage
src={src}
width={1280}
height={720}
effects={[
blur({
radius: interpolate(frame, [0, 100], [0, 40]),
}),
]}
/>❌ 避免通过条件判断包含 effect:
tsx
<CanvasImage
src={src}
width={1280}
height={720}
effects={enabled ? [blur({radius: 40})] : []}
/>将可编辑的 effect 参数内联放在无条件的 effect 调用中。不要通过变量传入坐标、颜色、数字控件或插值等可编辑值。
Interpolate rotation and translation directly
直接对旋转和位移进行插值
Interpolate CSS unit strings directly for and .
rotatetranslatePrefer:
tsx
style={{
rotate: interpolate(frame, [0, 100], ["20deg", "90deg"]),
translate: interpolate(frame, [0, 100], ["0px 0px", "100px 100px"]),
}}❌ Avoid manually building strings around separately interpolated numbers when the property can be interpolated directly.
Direct interpolation of these properties is supported and works better with visual editing in Studio.
对于 和 ,直接插值 CSS 单位字符串。
rotatetranslate推荐:
tsx
style={{
rotate: interpolate(frame, [0, 100], ["20deg", "90deg"]),
translate: interpolate(frame, [0, 100], ["0px 0px", "100px 100px"]),
}}❌ 如果属性可以直接插值,避免围绕分别插值得到的数字手动构建字符串。
这些属性支持直接插值,并且更适合在 Studio 中进行可视化编辑。
Use Interactive.*
for tweakable elements
Interactive.*对可调整元素使用 Interactive.*
Interactive.*Use the namespace from when an element is likely to be tweaked in Studio.
Interactiveremotiontsx
import {Interactive} from "remotion";For example:
tsx
<Interactive.Div
style={{
color: "red",
fontSize: 80,
}}
>
Hello
</Interactive.Div><Interactive.Div><Interactive.Span>Interactive.*Inline styles on these elements, such as text color and font size, can be standardized interactively.
如果某个元素可能需要在 Studio 中进行调整,请使用 中的 命名空间。
remotionInteractivetsx
import {Interactive} from "remotion";例如:
tsx
<Interactive.Div
style={{
color: "red",
fontSize: 80,
}}
>
Hello
</Interactive.Div><Interactive.Div><Interactive.Span>Interactive.*这些元素的内联样式,例如文本颜色和字体大小,可以通过交互方式统一标准化。