关于 elite-css-animations
elite-css-animations 是面向前端开发者的 CSS 动画参考 Skill,汇集滚动驱动动画、视图过渡、自定义属性和视觉效果的用法,并说明 CSS 与 GSAP 的适用场景。
主要功能
- 01滚动驱动动画参考
- 02View Transitions 用法
- 03@property 自定义属性动画
- 04clip-path 与 backdrop-filter 效果
- 05减少动效与性能实践
适用场景
- 01制作随滚动变化的进度条
- 02实现元素进入视口时的显现
- 03设计页面切换与悬停过渡
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ rshvr/ elite-web-design --skill elite-css-animations安装后在 Claude Code 中输入/elite-css-animations确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/property-rule.mdscroll-driven-api.mdview-transitions.mdvisual-effects.md详细介绍
精通 CSS 动画
现代 CSS 动画能力——无需 JavaScript 时的选择。
快速参考
| 主题 | 参考文件 |
|---|---|
| 滚动驱动 API | scroll-driven-api.md |
| 视图过渡 | view-transitions.md |
| @property 规则 | property-rule.md |
| 视觉效果 | visual-effects.md |
CSS 与 GSAP 选择指南
适合使用 CSS 的情况:
- 简单的显现/淡入动画
- 与滚动关联的进度指示器
- 悬停/聚焦状态过渡
- 性能至关重要(在主线程之外运行)
- Safari 支持并非关键(针对滚动驱动动画)
- 希望尽可能减少 JavaScript
适合使用 GSAP 的情况:
- 复杂的多元素序列
- 需要固定/粘滞行为
- 水平滚动版块
- 跨浏览器一致性至关重要
- 需要精细控制(带吸附的 scrub)
- 时间轴编排
混合方案
简单交互使用 CSS,复杂序列使用 GSAP:
/* CSS: Hover states, simple transitions */
.card {
transition:
transform 0.3s ease,
box-shadow 0.3s ease;
}
.card:hover {
transform: translateY(-4px);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}
// GSAP: Complex scroll-driven sequences
gsap
.timeline({
scrollTrigger: { trigger: ".section", scrub: 1 },
})
.from(".title", { opacity: 0, y: 50 })
.from(".content", { opacity: 0 }, "-=0.3");
浏览器支持(2026 年)
| 功能 | Chrome | Firefox | Safari | Edge |
|---|---|---|---|---|
| 滚动驱动动画 | ✓ 115+ | ✓ 132+ | ✗(polyfill) | ✓ 115+ |
| 视图过渡 | ✓ 111+ | ✗ | ✓ 18+ | ✓ 111+ |
| @property | ✓ 85+ | ✓ 128+ | ✓ 15.4+ | ✓ 85+ |
| clip-path 动画 | ✓ | ✓ | ✓ | ✓ |
| backdrop-filter | ✓ | ✓ | ✓ | ✓ |
滚动驱动动画快速入门
/* Progress bar that fills as you scroll */
.progress-bar {
transform-origin: left;
transform: scaleX(0);
animation: progress linear;
animation-timeline: scroll();
}
@keyframes progress {
to {
transform: scaleX(1);
}
}
/* Respect motion preference — show the full bar, no scroll-linked motion */
@media (prefers-reduced-motion: reduce) {
.progress-bar {
transform: scaleX(1);
animation: none;
}
}
/* Element reveals as it enters viewport */
@media (prefers-reduced-motion: no-preference) {
.reveal {
animation: fadeIn linear both;
animation-timeline: view();
animation-range: entry 0% cover 30%;
}
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
Safari Polyfill
<script src="https://flackr.github.io/scroll-timeline/dist/scroll-timeline.js"></script>
完整模式请参阅 scroll-driven-api.md。
视图过渡快速入门
// Simple page transition
document.startViewTransition(() => {
// Update the DOM
updateContent();
});
/* Customize the transition */
::view-transition-old(root) {
animation: fade-out 0.3s ease-out;
}
::view-transition-new(root) {
animation: fade-in 0.3s ease-in;
}
@keyframes fade-out {
to {
opacity: 0;
}
}
@keyframes fade-in {
from {
opacity: 0;
}
}
SPA 集成请参阅 view-transitions.md。
@property 快速入门
为以前无法添加动画的 CSS 自定义属性添加动画:
@property --progress {
syntax: "<number>";
initial-value: 0;
inherits: false;
}
.progress-circle {
--progress: 0;
background: conic-gradient(
var(--color-accent) calc(var(--progress) * 360deg),
transparent 0
);
transition: --progress 1s ease-out;
}
.progress-circle.complete {
--progress: 1;
}
渐变动画及更多内容请参阅 property-rule.md。
视觉效果快速入门
Clip-Path 显现
.reveal {
clip-path: inset(0 100% 0 0);
transition: clip-path 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.reveal.visible {
clip-path: inset(0 0 0 0);
}
Backdrop Filter
.glass {
backdrop-filter: blur(10px) saturate(180%);
background: rgba(255, 255, 255, 0.7);
}
Mix Blend Mode
.text-overlay {
mix-blend-mode: difference;
color: white;
}
创意模式请参阅 visual-effects.md。
prefers-reduced-motion
始终在偏好设置检查中包裹动画效果:
/* Default: No animation */
.animated {
opacity: 1;
transform: none;
}
/* Only animate if user allows */
@media (prefers-reduced-motion: no-preference) {
.animated {
animation: fadeIn 0.6s ease-out;
}
}
性能最佳实践
仅对合成器属性添加动画
/* GOOD - GPU accelerated */
.card {
transition:
transform 0.3s,
opacity 0.3s;
}
.card:hover {
transform: translateY(-4px) scale(1.02);
opacity: 0.9;
}
/* BAD - Triggers layout/paint */
.card:hover {
width: 110%;
margin-left: -5%;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
谨慎使用 will-change
/* Apply only during animation */
.animating {
will-change: transform, opacity;
}
/* Remove after animation */
.animation-complete {
will-change: auto;
}
contain 属性
/* Isolate expensive effects */
.animated-section {
contain: layout style paint;
}
常见模式
平滑悬停过渡
.card {
transition:
transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.card:hover {
transform: translateY(-4px);
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15);
}
错开入场
.item {
opacity: 0;
animation: fadeIn 0.5s ease forwards;
}
.item:nth-child(1) {
animation-delay: 0.1s;
}
.item:nth-child(2) {
animation-delay: 0.2s;
}
.item:nth-child(3) {
animation-delay: 0.3s;
}
/* ... or use CSS custom properties */
@keyframes fadeIn {
to {
opacity: 1;
}
}
加载微调器
.spinner {
width: 40px;
height: 40px;
border: 3px solid var(--color-border);
border-top-color: var(--color-accent);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
资源
评论
支持 Markdown