‹ 首页

animations

@clawic · 收录于 昨天 · 上游提交 2 天前

Create performant web animations with proper accessibility and timing.

适合你,如果需要为网站添加流畅且无障碍的动画效果。

/ 通过 npx 安装 校验哈希
npx oh-my-skill add clawic/skills/animations
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- clawic/skills/animations
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify clawic/skills/animations
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
14GitHub stars
~1.1K最小装载
~1.1K含声明引用
~1.1K文本包总量
索引托管

怎么用

商店整理自技能原文 · 版本 f825206 · 表述以原文为准
它做什么

Claude会根据本指南生成符合GPU加速、减少运动、合适计时函数和持续时间的CSS动画代码,并避免常见错误(如动画布局属性、无限循环等)。

什么时候触发

当用户要求创建或优化Web动画(如悬停效果、入场动画、页面过渡等),或询问动画性能最佳实践时触发。

装好后可以这样说
返回使用transform: scale和过渡的CSS代码
返回使用AutoAnimate库的React代码
返回使用CSS过渡的示例
技能原文 SKILL.md作者撰写 · MIT · f825206
GPU-Accelerated Properties

Only these properties animate on the compositor thread (60fps):

| Property | Use | |----------|-----| | transform | Move, rotate, scale (translateX, rotate, scale) | | opacity | Fade in/out |

Everything else triggers layout or paint. Avoid animating:

  • width, height, margin, padding (layout thrashing)
  • top, left, right, bottom (use transform instead)
  • border-width, font-size (expensive reflows)
/* ❌ Triggers layout every frame */
.slide { left: 100px; transition: left 0.3s; }

/* ✅ GPU accelerated */
.slide { transform: translateX(100px); transition: transform 0.3s; }
Reduced Motion

~5% of users experience vestibular disorders (dizziness, nausea from motion).

/* Only animate if user hasn't requested reduced motion */
@media (prefers-reduced-motion: no-preference) {
  .animated { animation: slide-in 0.5s ease-out; }
}

/* Or disable for those who requested it */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Keep subtle fades and color changes even with reduced motion. Remove parallax, bouncing, infinite loops.

Timing Functions

| Easing | Use case | |--------|----------| | ease-out | Elements entering view (appears responsive) | | ease-in | Elements exiting view (accelerates away) | | ease-in-out | Elements moving within view | | linear | Only for spinners, progress bars, color cycling |

/* Custom bounce */
transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);

/* Material Design standard */
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
Duration Guidelines

| Type | Duration | |------|----------| | Micro-interactions (hover, focus) | 100-200ms | | Transitions (modals, dropdowns) | 200-300ms | | Page transitions | 300-500ms | | Complex choreography | 500-1000ms max |

Anything over 500ms feels sluggish. Shorter is usually better.

CSS Transitions vs Animations

Transitions: A to B state changes

.button { transform: scale(1); transition: transform 0.2s ease-out; }
.button:hover { transform: scale(1.05); }

Animations: Multi-step, auto-play, looping

@keyframes fadeSlideIn {
  0% { opacity: 0; transform: translateY(20px); }
  100% { opacity: 1; transform: translateY(0); }
}
.card { animation: fadeSlideIn 0.5s ease-out forwards; }

Use transitions for hover/focus states. Use animations for on-load effects and sequences.

will-change

Only use as optimization when you have specific performance problems:

/* ✅ Apply before animation starts, remove after */
.card:hover { will-change: transform; }
.card { will-change: auto; }

/* ❌ Never apply globally */
* { will-change: transform, opacity; }  /* Wastes GPU memory */
Transition Property Specificity
/* ❌ Animates everything including unintended properties */
.card { transition: all 0.3s; }

/* ✅ Only animates what you need */
.card { transition: transform 0.3s, box-shadow 0.3s; }

all can cause unexpected animations on color, background, border changes.

React/Framework Traps

Exit animations require AnimatePresence:

/* ❌ Exit animation never plays */
{isVisible && <motion.div exit={{ opacity: 0 }} />}

/* ✅ Wrap conditional rendering */
<AnimatePresence>
  {isVisible && <motion.div exit={{ opacity: 0 }} />}
</AnimatePresence>

Stable keys for list animations:

/* ❌ Index keys cause erratic animations */
{items.map((item, i) => <li key={i}>{item}</li>)}

/* ✅ Stable IDs */
{items.map(item => <li key={item.id}>{item.text}</li>)}

AutoAnimate parent must be unconditional:

/* ❌ Ref can't attach to conditional element */
{showList && <ul ref={parent}>...</ul>}

/* ✅ Parent always renders, children are conditional */
<ul ref={parent}>{showList && items.map(...)}</ul>
Library Selection

| Library | Size | Best for | |---------|------|----------| | CSS only | 0kb | Hover states, simple transitions | | AutoAnimate | 3kb | Lists, accordions, toasts (90% of UI animations) | | Motion | 22kb | Gestures, physics, scroll animations, complex choreography | | GSAP | 60kb | Timelines, creative animation, scroll-triggered sequences |

Start with CSS. Add AutoAnimate for list animations. Only add Motion/GSAP for complex needs.

Common Mistakes
  • Animating width/height instead of scale—causes layout thrashing
  • Infinite animations without pause control—no way to stop
  • Same easing for enter and exit—use ease-out for enter, ease-in for exit
  • Ignoring prefers-reduced-motion—causes physical discomfort
  • Duration over 500ms—feels sluggish
  • transition: all catching unintended properties
  • Missing AnimatePresence for exit animations in React
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。