Scroll-triggered Animation new 滚动触发动画 Scroll-triggered web
An animation that starts when its element enters the viewport
元素进入视口时才开始播放的动画
标本可交互,可以直接操作。
Anatomy — every part, named解剖 —— 每个部件的名字
-
1 Visibility threshold可见阈值
IntersectionObserverThe point at which an element counts as visible enough to reveal.
元素达到足够可见程度、可以揭示的那个点。
Prompt fragmentPrompt 片段an IntersectionObserver threshold and rootMargin that trigger the reveal shortly before the card reaches the viewport
一个 IntersectionObserver threshold 和 rootMargin,让卡片在刚进入视口前后触发揭示
Prompt — paste into your agentPrompt —— 直接粘贴给你的代理
Add a scroll-triggered reveal to each card: use IntersectionObserver to add an in-view class when the card enters the viewport, animate opacity and translateY once, keep the final state visible, and provide a prefers-reduced-motion fallback that shows the card immediately.
给每张卡片加入滚动触发的揭示效果:用 IntersectionObserver 在卡片进入视口时添加 in-view 类,播放一次 opacity 和 translateY 动画并保留最终状态;在 prefers-reduced-motion 下直接显示卡片。
Debug prompt — when it misbehaves调试 Prompt —— 当它不听话时
Debug my scroll-triggered animation. Check that the observer uses a sensible threshold and rootMargin; the hidden initial state does not trap content when JavaScript fails; the animation is not retriggering on every scroll; cards remain visible after reveal; and prefers-reduced-motion skips the transform and opacity transition. The symptom:
调试我的滚动触发动画。检查 observer 的 threshold 和 rootMargin 是否合理;JavaScript 失败时隐藏初始状态不会把内容锁死;动画不会每次滚动都重播;揭示后卡片保持可见;prefers-reduced-motion 会跳过位移和透明度过渡。症状:
In code代码里叫什么
| Framework框架 | Symbol符号 | Note说明 |
|---|---|---|
| Web API | IntersectionObserver | detect viewport entry without polling scroll position无需轮询滚动位置,检测元素进入视口 |
| CSS | @keyframes + animation | define the reveal motion and timing定义揭示动效和时间 |
| CSS | prefers-reduced-motion | show content without motion when requested用户要求减少动态效果时直接显示内容 |