← 工具集

界面打磨

可中断动效 · 按压缩放 · 进出场 · 图标动效纪律 · 动效克制 — 与「界面质感」的静态规则互补。

一、动效必须可中断

CSS 过渡CSS 关键帧
行为朝最新状态插值固定时间线跑完
被打断中途改向、平滑反演跳变或从头重放
用途hover / toggle / 开合一次性的序列(进场、加载)
.drawer{ transform:translateX(-100%); transition:transform 200ms ease-out; }
.dwer.open{ transform:translateX(0); }     /* 中途再点会平滑反转 */
/* 坏:.open 用 animation 关键帧,关到一半会 snap */
交互元素一律用 CSS 过渡;关键帧只留给定好的一次性序列。

二、按压缩放(scale .96)

点击时轻微缩到 0.96,绝不小于 0.95(更小显得夸张)。用过渡保证可中断:松手中途也能平滑回弹。

.button{ transition-property:scale; transition-duration:150ms; transition-timing-function:ease-out; }
.button:not(:disabled):active{ scale:.96; }
始终用 scale(.96),给按钮加 static 属性在会分心时关掉。

三、进出场:拆分 + 错峰

  1. 拆成语义组(标题 / 描述 / 动作)。
  2. 组间错峰 100ms。
  3. 短标题再按词拆,词间 80ms。
  4. 每组组合 opacity + blur(4px) + translateY(12px)。
.stagger-item{ animation:fade-in 300ms ease-out both; }
@keyframes fade-in{ from{ opacity:0; transform:translateY(12px); filter:blur(4px);} }
@media (prefers-reduced-motion: no-preference){ .stagger-item{ animation-name:fade-in-up; } }
退场比进场短且低调:translateY(-12px)+blur(4px),150ms(进场 300ms)。用户注意力已移向下一处,别抢戏。需保留空间含义时(卡片回列表、抽屉关)才整段滑出(x:-100%,200ms)。

四、图标动效纪律(固定数值)

上下文出现的图标(hover 显现、状态切换)用 opacity + scale + blur 交叉淡入,禁用其它值:

属性起→止
scale0.25 → 1(绝不用 0.5/0.6)
opacity0 → 1
filterblur(4px) → blur(0px)
transition{ type:'spring', duration:0.3, bounce:0 } —— bounce 恒为 0
// 无 motion 依赖:两图标同 DOM 交叉淡
Active
Inactive
检查项目 package.json:装了 motion 从 motion/react 引,装了 framer-motion 从它引,两者皆无就用 CSS 交叉淡——别为图标动效加依赖。
该动不该动
hover 才出现的动作图标静态导航图标
状态切换(播放↔暂停、赞↔已赞)装饰图标
上下文工具栏图标始终可见的图标
♡
点赞切换:用 outline→fill 状态对,不要两个都 fill。

五、动效克制

.panel{ transition:opacity 150ms ease-out; }
@media (prefers-reduced-motion: no-preference){
  .panel{ transition-property:opacity, translate, scale, filter; transition-duration:300ms; }
}

Tailwind 里给位移/缩放/模糊加 motion-safe: 前缀;Motion 用 <MotionConfig reducedMotion="user">(保留 opacity,关掉 transform/layout,blur 仍需按 useReducedMotion() 分支)。