本周新品查看全部
Stagger fade-up
错峰淡入上移
Let a group of elements enter one after another.
Also searched as: 卡片一个个出现, 卡片一个接一个出现, 列表依次出现, 一组东西挨个冒出来, 错峰入场
- Placement
- Card list
- Mood
- Crisp, Soft
- Trigger
- 进入屏幕
- Site types
- 作品集, 电商, 博客
How it works & accessibility
Animate each item from a lower, transparent state to its final position, offsetting the start of each item.
Best for: Card list (进入屏幕).
Reduced motion: 不播放动画,所有元素直接显示
Mobile & touch: 和桌面一样;排成一列时,间隔可以小一点
Key parameters
| Parameter | Key | Default | Range | Notes |
|---|---|---|---|---|
| 每个时长 | duration | 500ms | — | — |
| 前后间隔 | stagger | 75ms | — | — |
| 上移距离 | distance | 16px | — | — |
| 缓动 | easing | cubic-bezier(0.16, 1, 0.3, 1) | — | — |
Ready-to-paste AI prompt
Add “Stagger fade-up” to the card list in my project: Animate each item from a lower, transparent state to its final position, offsetting the start of each item.
Parameters: duration: 500ms, stagger: 75ms, distance: 16px, easing: cubic-bezier(0.16, 1, 0.3, 1).
Preserve existing content and layout. Respect prefers-reduced-motion by showing the final state. Content must remain visible if JavaScript fails or is disabled.
Reference: https://donglang.linter.top/effects/stagger.md (canonical specification and reference code).Dependency-free reference code
CSS
/* 错峰淡入上移不需要额外的样式:元素默认就是最终的样子,动画开始前那一瞬才由脚本藏起来 */JavaScript
// 错峰淡入上移(Stagger fade-up)· 原生 JS,不依赖任何库。
// 改写自 StyleKit 的 stagger-children(MIT License,Copyright (c) 2026 AnxForever):入场动作和默认值来自它。
// list 是一组元素的外层,里面每个直接子元素依次淡入、上移到原位。返回一个清理函数:调用它会停掉动画,元素回到原位。
// 开启"减少动态"时不播放,直接显示;动画用 fill: 'backwards',脚本出错或没执行时内容照样可见。
// ignoreReducedMotion 只给"用户主动点播放"的演示用,网站自己的列表不要打开它。
export function staggerIn(list, {
duration = 500,
stagger = 75,
distance = 16,
easing = 'cubic-bezier(0.16, 1, 0.3, 1)',
ignoreReducedMotion = false,
} = {}) {
if (!ignoreReducedMotion && matchMedia('(prefers-reduced-motion: reduce)').matches) return () => {};
const animations = [...list.children].map((item, i) => item.animate(
[{ opacity: 0, transform: `translateY(${distance}px)` }, { opacity: 1, transform: 'none' }],
{ duration, delay: i * stagger, easing, fill: 'backwards' },
));
return () => animations.forEach((a) => a.cancel());
}
// 列表进入屏幕时播放一次。
// 离屏幕底边还有 40px 时就开始(碰到一点就算):动画的第一帧是藏起来的,等露出一截再开始,会先完整露一下、再消失、再进场;
// 按露出的比例算,比屏幕还高的元素可能永远够不到比例、一直不播。root: document 让提前量按元素所在页面自己的视口算,放在 iframe 里也管用
export function staggerOnEnter(list, options) {
const io = new IntersectionObserver(([entry]) => {
if (!entry.isIntersecting) return;
io.disconnect();
staggerIn(list, options);
}, { root: document, threshold: 0, rootMargin: '0px 0px 40px 0px' });
io.observe(list);
return () => io.disconnect();
}HTML
<!-- 错峰淡入上移:一组元素放在同一个外层里,外层里的每个直接子元素依次出现 -->
<ul class="cards" id="cards">
<li>第一张卡片</li>
<li>第二张卡片</li>
<li>第三张卡片</li>
</ul>
<script type="module">
import { staggerOnEnter } from './stagger.js';
staggerOnEnter(document.getElementById('cards'));
</script>