Skip to content

176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.

fix: keep 2.5D / Pseudo-3D's moon in view on short stages

matin7f01dfca8085
diff --git a/animations/06-3d-advanced/2-5d-pseudo-3d/README.md b/animations/06-3d-advanced/2-5d-pseudo-3d/README.md
index ea890923..b0273d7f 100644
--- a/animations/06-3d-advanced/2-5d-pseudo-3d/README.md
+++ b/animations/06-3d-advanced/2-5d-pseudo-3d/README.md
@@ -10,7 +10,7 @@
- Interactive maps or environments where camera movement reveals depth
## How it works
-Each layer has a CSS `transform: translateX(offset)` where offset = `mouseNormalizedX * strength * depth`. Layers at depth 0 don't move; depth 1 moves the maximum amount:
+Each layer has a CSS `transform: translate(x, y)` that slides it the opposite way from the pointer: x = `-normX * strength * depth` and y = `-normY * strength * depth * 0.4`, where `normX` and `normY` are the pointer's position across the stage, from -0.5 to 0.5. Layers at depth 0 don't move; depth 1 moves the maximum amount:
```js
const LAYERS = [
diff --git a/animations/06-3d-advanced/2-5d-pseudo-3d/index.html b/animations/06-3d-advanced/2-5d-pseudo-3d/index.html
index ae1d4b9b..fa81aac2 100644
--- a/animations/06-3d-advanced/2-5d-pseudo-3d/index.html
+++ b/animations/06-3d-advanced/2-5d-pseudo-3d/index.html
@@ -23,7 +23,7 @@
<style>
:root{--ui-accent:#3fd6c4}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
- .stage{position:relative;cursor:none;touch-action:pan-y}
+ .stage{position:relative;cursor:none;touch-action:pan-y;container-type:size}
/* 3D scene container */
.scene{width:100%;height:100%;position:relative;perspective:800px;perspective-origin:50% 50%;overflow:hidden}
.scene-inner{width:100%;height:100%;position:relative;transform-style:preserve-3d;transform:translateZ(0);transition:transform 0ms linear}
@@ -51,6 +51,9 @@
.fog{position:absolute;bottom:28%;left:-60px;right:-60px;height:56px;background:linear-gradient(transparent,rgba(10,30,60,.4) 60%,rgba(10,30,60,.6))}
/* Moon */
.moon{position:absolute;top:15%;right:20%;width:36px;height:36px;border-radius:50%;background:#d8e8f8;box-shadow:0 0 20px rgba(200,220,255,.4)}
+ /* On a stage under about 360px tall the far mountains reach up to the moon (their sizes are fixed), so the moon moves up
+ and into the corner, above the highest peaks, where none of them can cover it at any stage width */
+ @container (max-height:360px){.moon{top:4%;right:6%}}
/* Cursor ring: moved with a transform, from the stage's top left corner */
#cursor{position:absolute;left:0;top:0;width:20px;height:20px;border-radius:50%;border:2px solid var(--ui-accent);pointer-events:none;z-index:100;display:none}
/* Depth labels: shown by the Layer labels switch, one line each in the top left corner, placed by the script.
@@ -202,7 +205,9 @@
const starLayer=document.getElementById('L1');
for(let i=0;i<80;i++){
const s=document.createElement('div');s.className='star';
- s.style.cssText=`width:${Math.random()*2+1}px;height:${Math.random()*2+1}px;top:${Math.random()*60}%;left:${Math.random()*100}%;opacity:${.3+Math.random()*.7}`;
+ // no star in the top left corner, where the "moves 5%" label sits
+ let y,x;do{y=Math.random()*60;x=Math.random()*100}while(y<8&&x<30);
+ s.style.cssText=`width:${Math.random()*2+1}px;height:${Math.random()*2+1}px;top:${y}%;left:${x}%;opacity:${.3+Math.random()*.7}`;
starLayer.appendChild(s);
}
diff --git a/docs/superpowers/plans/2026-09-29-3d-content.md b/docs/superpowers/plans/2026-09-29-3d-content.md
index cf255cb0..86404ad8 100644
--- a/docs/superpowers/plans/2026-09-29-3d-content.md
+++ b/docs/superpowers/plans/2026-09-29-3d-content.md
@@ -951,18 +951,20 @@ None: leave out the `details.hb-options` block.
- **Reset:** stops a run, sets `mx = my = 0` and calls `applyParallax(0,0)` (today's Reset camera, without the readout).
- **Sequence:** the Mode menu and `autoLoop()` go (Auto-pan becomes Show me). The pointer moves the camera as today (`pointermove` → `applyParallax(mx,my)`), and the camera stays where the pointer leaves it, as today.
- **Reduced motion:** Show me does not run on arrival. The page's `motionOk` branch goes with the Mode menu. The rule `.scene-inner{transition:none!important}` can stay (it changes nothing).
-- **Stage font:** site font. The layer labels get 11px and `font-weight:600` (were 8px) and read "moves 5%" to "moves 100%" (were "depth 0.05" to "depth 1.0"). Their stagger becomes `top = 4 + i*16` px so the larger labels do not overlap, and `MAX_PAN` becomes 35 (half the largest Camera movement; the slider it read goes). The labels move to the top-left corner (`left` in place of `right`, with the same inset, `6 + pad + MAX_PAN*depth`): on the right, their column crossed the moon on phones. Checked at the laptop, tablet and both phone stages: every label stays clear of the moon.
+- **Stage font:** site font. The layer labels get 11px and `font-weight:600` (were 8px) and read "moves 5%" to "moves 100%" (were "depth 0.05" to "depth 1.0"). Their stagger becomes `top = 4 + i*16` px so the larger labels do not overlap, and `MAX_PAN` becomes 35 (half the largest Camera movement; the slider it read goes). The labels move to the top-left corner (`left` in place of `right`, with the same inset, `6 + pad + MAX_PAN*depth`): on the right, their column crossed the moon on phones. Checked at the laptop, tablet and both phone stages: every label stays clear of the moon. The labels sit on a dark backing (`padding:0 5px;border-radius:4px;background:rgba(2,8,18,.75)`) and their text is `rgba(255,255,255,.7)` (was .5): stars are bright dots, and a star behind a letter of the .5 text with no backing took it down to 1.0 to 1.2:1 (measured on the letters' own pixels); with the backing and .7 the worst pixel of labels 1 to 6 is at least 5.7:1 over 60 pictures (page loads, sizes and camera positions).
- **Stage:**
- - The seven layers, the custom cursor ring and the labels stay. `cursor:none` and `touch-action:pan-y` stay.
+ - The seven layers, the custom cursor ring and the labels stay. `cursor:none` and `touch-action:pan-y` stay. The ring is moved with `transform` (`#cursor{left:0;top:0}` and `translate(x - 10px, y - 10px)` from the stage's top left corner), not with `left` and `top`, so the page moves nothing but transforms. The scene has `role="img"` and an `aria-label` in plain words ("A night landscape of seven flat layers, from the sky to the ground, that slide by different amounts as the camera moves"), as the cube on Scroll-Driven 3D Rotation has.
- **A smaller scene.** The scene was drawn for a 620px stage: on the shared 300–440px stage the mountains' peaks are cut off and the moon hides behind the hills. Its fixed sizes shrink to about 0.7 (the hills to 0.6), previewed at the laptop, tablet and both phone stages with the peaks, the moon and the tree line all in view:
- `.mtns-far` (inline style): height 200px → 140px;
- the six mountains' inline `border-width:0 W H`: 100/160 → 70/112, 80/120 → 56/84, 120/180 → 84/126, 90/140 → 63/98, 110/160 → 77/112, 70/100 → 49/70;
- `.hills-wrap` 180px → 108px, and the second one's inline 130px → 78px;
- `.fog` 80px → 56px; `.moon` 50px → 36px;
- `addTrees('trees-far',14,25,…)` and `addTrees('trees-near',8,39,…)` (were 36 and 56).
+ - **The moon moves up on short stages (fix round 1).** The mountains' sizes are fixed pixels, so on a short stage their peaks reach the moon at `top:15%;right:20%`, which the previews above did not catch: they used the 300px, 327px, 380px and 440px stages (the moon was in view there, a fifth of it behind a peak on the 300px and 327px ones) and never a 258px stage. Measured on pixels (the moon's own pixels against the scene as drawn, camera at rest), the hidden part of the moon was 100% at 1280×590 (a 258px stage), 84% at 896×414, 63% at 812×375, 26% at 667×375, 19% at 1366×657, 20% at 375×812 and 16% at 320×640. So the stage gets `container-type:size` and, after the `.moon` rule, `@container (max-height:360px){.moon{top:4%;right:6%}}`. A stage 361px or taller keeps the moon where it was (it is clear from there up, at every width), and a browser without container queries keeps the old position. The numbers come from a sweep of the geometry (the 36px moon against the six triangles, with the camera at rest and at its four corners with Large movement, for a phone's 298px stage 286 to 566px wide and every stage 258 to 360px tall and 551 to 958px wide): the peak nearest the moon on the phone stage is 47px from the top, so `top:4%` clears it at every width, and the peaks at 30% and 70% reach 6px and 20px from the top of a 258px stage, so `right:6%` keeps the moon clear of both at every width. The first candidates left part of the moon hidden at some width: `top:6%;right:8%` (16% of the moon on a 551px-wide 258px stage, 4% on a phone stage 364 to 500px wide) and a 280px limit (nothing done for the 300px and 325px stages, where 16 to 23% stayed hidden). Measured the same way on pixels, at rest and at the four camera corners with Large movement, none of the moon is hidden at 1280×590, 896×414, 812×375, 667×375, 1366×657, 375×812, 320×640, 360×640, 412×915, 480×320, 1024×768, 1280×800, 768×1024, 1440×900 and 25 more sizes from 320 to 1600 wide.
+ - **No star over the "moves 5%" label (fix round 1).** The sky is the lowest layer, so a star (one layer up) could pass over its label; in review that happened on 20% of the page loads at 1280×800, 30% at 1280×590, 67% on a 375px phone and 43% on a sideways phone. The star loop draws a star's position again while `top<8%` and `left<30%` (that corner holds the label at every stage size and camera position), so there are still 80 stars. Over ten loads at each of five sizes (1280×800, 1280×590, 375×812, 320×640, 812×375) no star sits in the corner and none touches the label at any camera position (before: 22 to 42 stars in the corner per ten loads).
- `hb-dots`: no. Default height.
- **Phone fallback:** none needed: seven layers moved with transforms (a continuous pan measured 0.6ms a frame on the throttled phone).
-- **Touch:** `pointerdown` also sets the camera (today only `pointermove` does), so a tap moves it; a sideways drag keeps moving it.
+- **Touch:** `pointerdown` also sets the camera (today only `pointermove` does), so a tap moves it; a sideways drag keeps moving it. The camera is held between −0.5 and 0.5 on both axes (`edge()`): a finger dragged off the stage keeps sending its moves to the stage, and the label insets (`MAX_PAN`) and the layers' overscan assume no more than that.
**Main settings**
@@ -1002,7 +1004,7 @@ None: leave out the `details.hb-options` block.
- [Parallax Depth-of-Field](../../01-scroll-based/parallax-depth-of-field/) — the same layered depth, driven by scrolling
- [Parallax 3D Tilt](../parallax-3d-tilt/) — one card leans toward the pointer
- [Scroll-Driven 3D Rotation](../scroll-driven-3d-rotation/) — scrolling moves a 3D object
-- **README How it works:** two changes, so the snippets match the demo:
+- **README How it works:** three changes, so the prose and the snippets match the demo:
- The first snippet listens for `pointermove`, as the demo does, and measures the pointer against the stage's box. Its first three lines become these four:
```js
@@ -1026,6 +1028,8 @@ None: leave out the `details.hb-options` block.
}
```
+ - The paragraph before the first snippet says how the transform is made, as the code makes it: "Each layer has a CSS `transform: translate(x, y)` that slides it the opposite way from the pointer: x = `-normX * strength * depth` and y = `-normY * strength * depth * 0.4`, where `normX` and `normY` are the pointer's position across the stage, from -0.5 to 0.5." (it said `translateX(offset)` with `offset = mouseNormalizedX * strength * depth`). After the first snippet a sentence says the demo has seven layers and listens for `pointerdown` too, and after the Show me snippet a sentence says the demo blends in the camera's starting position and that Reset puts the camera back in the middle.
+
The rest is unchanged.
- **README Production notes:** in the Scroll-driven variant bullet, "replace `mousemove` with `scroll`" becomes "replace `pointermove` with `scroll`", to match the snippet. The rest is unchanged.
- **Category line:** `06.11 · 3D &amp; Advanced`