“the background that moves slower than the content”「比内容移动更慢的背景」
“layers drifting at different speeds”「以不同速度漂移的图层」
“a landscape with depth while scrolling”「滚动时有纵深感的风景」
“the image that lags behind the text”「滞后于文字移动的图片」
PARALLAXDepth by distance
backgroundforeground
标本可交互,可以直接操作。
Anatomy — every part, named解剖 —— 每个部件的名字
1Depth layer纵深图层transform: translate3d()
One independently moving plane in the scene.
场景中独立移动的一个平面。
Prompt fragmentPrompt 片段
a background, midground, or foreground layer with a small scroll-mapped transform and no layout reflow
一个背景、中景或前景图层,带小幅滚动映射 transform 且不触发布局重排
Prompt — paste into your agentPrompt —— 直接粘贴给你的代理
Create a restrained parallax scene with separate background, midground, and foreground layers. Map scroll progress to small transform offsets, keep the focal content readable, avoid large motion that causes discomfort, and flatten the layers under prefers-reduced-motion.
Debug prompt — when it misbehaves调试 Prompt —— 当它不听话时
Debug my parallax effect. Check that each layer has a stable containing block, transforms do not create horizontal overflow, updates are frame-scheduled, the movement range is subtle, images have reserved dimensions, and reduced motion disables the depth travel while preserving the scene. The symptom:
# Parallax Scrolling · 视差滚动 Parallax
UI reference — https://K3tty5555.github.io/LearnUI_PM/web/parallax/
**Layered motion where foreground and background travel at different rates**
前景与背景以不同速度移动的分层滚动效果
**Also called / 也叫:** parallax effect, depth scroll, multi-plane scroll / 视差效果、纵深滚动、多平面滚动
## Anatomy — every part, named / 解剖
1. **Depth layer · 纵深图层** (`transform: translate3d()`)
One independently moving plane in the scene.
场景中独立移动的一个平面。
Prompt fragment: a background, midground, or foreground layer with a small scroll-mapped transform and no layout reflow
## Prompt / 提示词
Create a restrained parallax scene with separate background, midground, and foreground layers. Map scroll progress to small transform offsets, keep the focal content readable, avoid large motion that causes discomfort, and flatten the layers under prefers-reduced-motion.
创建一个克制的视差场景,分开背景、中景和前景图层。将滚动进度映射到小幅 transform 偏移,保持主体内容可读,避免大幅移动造成不适,并在 prefers-reduced-motion 下压平图层。
## Debug prompt / 调试提示词
Debug my parallax effect. Check that each layer has a stable containing block, transforms do not create horizontal overflow, updates are frame-scheduled, the movement range is subtle, images have reserved dimensions, and reduced motion disables the depth travel while preserving the scene. The symptom:
调试我的视差效果。检查每个图层有稳定的包含块;transform 不会制造横向溢出;更新按帧调度;移动范围足够克制;图片预留尺寸;减少动态效果时关闭纵深移动但保留场景。症状:
## In code / 代码里叫什么
- **CSS** `transform: translateY()` — move layers without reflow / 移动图层而不触发布局重排
- **Web API** `requestAnimationFrame` — schedule scroll position updates efficiently / 高效调度滚动位置更新
- **CSS** `prefers-reduced-motion` — flatten layers when motion is reduced / 减少动态效果时压平图层