动画看起来不自然,很多时候不是时长写错了,而是曲线与动作的角色不匹配。

弹窗用 ease-in 入场,会先停顿一下再突然出现;Toast 用 ease-out 离场,会慢悠悠地不肯走;一个应该跟随手指的拖拽却加了缓动,会立刻显得“不跟手”。

缓动曲线描述的是进度如何随时间推进,曲线的切线斜率才是某一刻的速度。曲线越陡,位移推进得越快;曲线越平,动作越慢。选择曲线,本质上是在选择动作应该如何开始、如何结束。

先判断动作的角色

不要先问“这个组件应该用哪条贝塞尔曲线”,先问它正在做什么:

  • 从无到有地出现;
  • 从有到无地离开;
  • 留在页面里,只改变位置或尺寸;
  • 对一次点击做即时确认;
  • 跟随指针或手指;
  • 松手后回到某个稳定位置;
  • 持续运行,没有明确的起点和终点。

同一个组件可能同时拥有多种动作。Dialog 的入场和退场可以用不同曲线;拖动排序时,手指跟随与松手归位也不能共用一段动画。

一套按角色分配的曲线

产品里只维护少量曲线 token,让同一类动作在全站共用同一条节奏。

角色 曲线 典型场景
入场 --ease-out Toast、菜单、Popover、Dialog、Drawer
点击后的跟手落位 --ease-out-strong 图标、文字、选中的胶囊
退场 --ease-in 弹窗关闭、Toast 消失、菜单收起
原地移动 --ease-in-out 指示条滑动、轮播翻页、排序避让
小型确认 --ease-overshoot 勾选、点赞、角标弹出、开关归位
手势释放 --ease-spring 底部面板吸附、卡片回弹、下拉刷新
持续运行 linear 进度条、加载环、跑马灯

可以先把曲线与时长写成 token:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
:root {
--ease-out: cubic-bezier(0, 0, 0.58, 1);
--ease-out-strong: cubic-bezier(0.22, 1, 0.36, 1);
--ease-in: cubic-bezier(0.42, 0, 1, 1);
--ease-in-out: cubic-bezier(0.42, 0, 0.58, 1);
--ease-overshoot: cubic-bezier(0.34, 1.56, 0.64, 1);
--ease-spring: linear(
0,
0.32,
0.78,
1.04,
1.09,
1.06,
1.02,
1,
0.99,
0.99,
1
);

--duration-sm: 180ms;
--duration-md: 300ms;
--duration-lg: 420ms;
}

组件只按角色引用 token,不再各自手调一条曲线。CSS 默认的 ease 不是设计决定;凡是让元素移动、出现或消失的地方,都应该明确选择。

入场用 ease-out,退场用 ease-in

入场是元素来到最终位置。ease-out 起步快、结束慢,视觉上会先响应,再柔和地停下,适合 Toast、菜单、Popover、Dialog 和 Drawer。

小元素在点击后立即落位时,可以使用更陡的 --ease-out-strong。图标、标签和选中胶囊会更快接住操作,收尾仍然稳定。

退场则相反。ease-in 起步慢、结束快,元素会先准备离开,再干脆地消失。它不适合入场,因为缓慢的起步会让人以为界面卡了一下。

入场和退场也不应该等长。用户已经知道正在消失的内容是什么,因此退场通常可以更短:

  • 小型界面入场约 150–250ms,退场约 120–200ms;
  • Dialog、带内容的 Popover 与 Drawer 约 250–350ms;
  • 全屏面板与页面切换约 350–500ms;
  • Spring 与 Overshoot 因为包含回稳过程,可以约为普通时长的 1.5 倍。

入场方向要说明它从哪里来

曲线只管速度,位移方向还要说明空间关系。

Toast 从顶部边缘来,菜单从触发按钮附近展开,Drawer 从依附的屏幕边缘进入。移动距离通常在 8–24px 之间,视觉尺寸从约 96% 开始,并与淡入同步;透明度可以略早完成,让内容先清晰,再落稳。

退场沿同一条路径反向离开,但时间更短。

如果几个元素在同一个区域内依次落位,可以让内部的小图标、文字或数字晚 100–200ms,用 --ease-out-strong 跟上。它们形成先后节奏,但不要为每个元素单独编排一套互不相关的曲线。

留在屏幕里的移动用 ease-in-out

标签下方的指示条、分段控件、轮播翻页、目录平滑滚动和排序时的避让,都是“元素已经存在,只是在页面上换位置”。

这类动作适合 ease-in-out:慢起、中间快、慢停。它让起点和终点都清楚,不会像掉帧一样突然闪现。

但入场不要使用 ease-in-out。用户刚执行操作时界面缓慢起步,会被理解为延迟;ease-out 的快起慢停才更像立即响应。

跟手阶段不要加缓动

拖动、滑动和下拉过程中,元素必须 1:1 跟随指针或手指,不能为了“顺滑”再套一层缓动。

缓动属于释放之后。松手时,动画应从当前的释放速度继续,再通过 Spring 收敛到目标位置。动画库支持速度参数时优先使用它;没有库时,再用 --ease-spring 的 linear() token 近似。

拖动排序、底部面板吸附、半滑卡片回位、下拉刷新,都遵循同一因果:手指控制过程,Spring 接管结果。

Overshoot 只留给小型确认

--ease-overshoot 会冲过终点约 10%,再退回来。它适合勾选、点赞、角标和开关这类小型、可重复且反馈明确的动作。

不要把它用在大面板、Dialog 或 Drawer 上,也不要用于用户一天要执行几十次的功能。尺寸越大,越像失控;频率越高,越容易成为干扰。

Spring 比 Overshoot 更像真实物体,因为它允许一两次幅度逐渐衰减的回摆。它适合手势释放后的归位,但不应该成为所有动画的默认曲线。

动画不能阻塞下一次操作

动画期间界面仍然要接受输入。新的操作应该从当前视觉状态打断旧动画,再前往新目标,而不是等旧动画播放完,也不是跳回初始状态重播。

悬停与按压反馈可以控制在 100–150ms 的 ease-out。悬停不要改变宽高、边距或布局位置;使用 transform、opacity,必要时少量使用 filter。top、left、width、height 会触发布局与重绘,不适合逐帧变化。

减少动态效果不是关闭状态反馈

在 prefers-reduced-motion: reduce 下,应该保留透明度变化和颜色变化,去掉位移与缩放,把 Spring 和 Overshoot 降为约 150ms 的普通淡入淡出。

减少动态效果的目标是降低前庭负担,不是让所有状态变化一起消失。用户仍然需要知道菜单打开了、操作完成了、错误出现了。

先审计,再换曲线

调整动效前,先把现有的 CSS transition、keyframes、动画库配置、Web Animations API 调用和手写 requestAnimationFrame 循环列出来。

每一项都记录组件、触发方式、距离、时长和当前曲线。特别标出三类问题:

  • 没有设置曲线,落回 CSS 默认 ease;
  • 应该在跑的持续动画使用了非 linear 曲线;
  • 入场元素使用了 ease-in 或 ease-in-out。

先交付角色与曲线映射,再统一替换 token。不要借改曲线的机会改变动画发生了什么、移动了多远或由什么触发。

检查清单

  • 每个动画是否先有明确角色,再选择曲线;
  • 入场是否使用 ease-out,退场是否使用更短的 ease-in;
  • 原地移动是否使用 ease-in-out;
  • 小型确认是否才使用 Overshoot;
  • 手势是否先 1:1 跟手,释放后才启用 Spring;
  • 同一角色是否全站共用一条曲线和时长 token;
  • 是否清理了未设置的 CSS 默认 ease;
  • 是否会动画 transform 和 opacity,而不是布局属性;
  • 动画是否可被新操作从当前状态打断,且不阻塞输入;
  • 减少动态效果时是否保留状态反馈,只移除位移、缩放与回摆。

动画节奏示例 Prompt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Prompt (1)

Give the motion in my product the right easing curves, so things arrive, leave and move the way they should feel. Work inside my existing code and design system: keep what each animation does, how far it goes and what triggers it. Change how it moves over time, and its duration where that is off.

0. Start from what exists
- Find every transition and animation: CSS transitions and keyframes, animation libraries (Framer Motion, GSAP, the Web Animations API) and hand-written requestAnimationFrame loops. List each with its component, its trigger, its duration and its curve.
- Flag the ones left on the CSS default `ease`, `linear` on something that moves, and `ease-in` on something that appears.

1. The curves as tokens
Define them once, next to the other motion tokens, and use only these:
- --ease-out: cubic-bezier(0, 0, .58, 1). Anything that enters: toasts, menus, popovers, dialogs, drawers.
- --ease-out-strong: cubic-bezier(.22, 1, .36, 1). Small parts settling in right after a click: an icon, a label, a selected pill. It feels the most responsive.
- --ease-in: cubic-bezier(.42, 0, 1, 1). Anything that leaves, and only that: a toast timing out, a dialog or drawer closing, a menu collapsing, a list item swiped away. It starts slow and leaves at full speed, so on an entrance it feels late and then stops with a bump.
- --ease-in-out: cubic-bezier(.42, 0, .58, 1). Something that stays on screen and only changes place or size: the indicator under tabs or a segmented control, a carousel turning a page, items making room during a reorder, a sidebar resizing, smooth-scrolling to an anchor. Not for coming in: its slow start reads as lag.
- --ease-overshoot: cubic-bezier(.34, 1.56, .64, 1). Runs about 10% past its place and comes back. Small, playful confirmations: a checkbox tick, a like, a badge count popping in, a switch knob settling. Never on a dialog, a drawer or anything larger than about 64px, and not on actions people repeat all day.
- --ease-spring: linear(0, .32, .78, 1.04, 1.09, 1.06, 1.02, 1, .99, .99, 1). Things let go after a drag or a swipe, so they settle like an object: a bottom sheet snapping open or back, a card returning after a half swipe, pull-to-refresh springing back, a reordered item dropping into place. Prefer the animation library's own spring fed with the release velocity; use this token only where there is none, and fall back to --ease-out-strong where linear() is not supported.
- linear: only for things that run rather than move: spinners, progress bars, marquees.
- The CSS default `ease` is not a choice. Replace it wherever a curve was left unset.

2. Durations
- Small UI (toasts, tooltips, menus, checks): 150-250ms in, 120-200ms out. Exits are shorter than entrances.
- Medium (dialogs, popovers with content, drawers): 250-350ms.
- Large or full-screen (sheets, page transitions): 350-500ms. Longer feels slow.
- Springs and overshoots: about 1.5x the plain duration, since the settle takes time.
- Keep the durations as tokens beside the curves (--duration-sm, -md, -lg).

3. Apply them by role
- Entrances: ease-out, coming from where the thing belongs (a toast from the top edge, a menu from its trigger), over a short distance (8-24px), growing from 96% and fading in a little sooner than it moves. A light blur (about 8px) that clears as it lands is a nice touch on toasts.
- Exits: ease-in, the same path reversed, and shorter.
- Moves on screen: ease-in-out.
- Parts inside something that has just appeared (its icon, its text, a count) may follow 100-200ms later on the strong ease-out, so it lands in steps rather than all at once.
- Gestures: while the pointer or finger moves, follow it 1:1 with no easing. On release, finish on the spring, from the release velocity if the library allows.
- Hover and press: 100-150ms ease-out. Never animate layout on hover.
- Animate transform and opacity (filter sparingly), not top, left, width or height, which lay out and repaint every frame.

Prompt (2)

4. Keep it consistent and accessible
- One curve per role across the product. Don't tune each component by hand.
- Respect prefers-reduced-motion: keep the opacity changes, drop movement and scale, and turn springs and overshoots into a plain 150ms fade.
- Never make a user wait on an animation: nothing blocks input, and a new action interrupts the old animation from where it is.

5. Deliver
- First list every animation you found, its current curve and duration, and the role and curve you will give it.
- Then add the tokens, switch each animation over, and list every file you touched.
- Don't change what animates, how far it goes or what triggers it. If an animation has no clear role, ask me first.

质感来自可解释的细节

动画节奏不是把每个组件调成相近的毫秒数,而是让动作与它的因果一致。

出现时快速响应,离开时干脆收场;留在页面里的移动说明空间变化,手势过程完全跟手,释放之后才交给 Spring;持续运行的元素只负责稳定前进。曲线选对了,动画就不需要被注意到,它只会让界面显得理所当然。

站内搜索

没有找到内容!