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.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
feat: move Scroll-Driven 3D Rotation to the guided-steps page
matin94d1df18e41f
diff --git a/animations/06-3d-advanced/scroll-driven-3d-rotation/README.md b/animations/06-3d-advanced/scroll-driven-3d-rotation/README.mdindex b08c22c3..9910eded 100644--- a/animations/06-3d-advanced/scroll-driven-3d-rotation/README.md+++ b/animations/06-3d-advanced/scroll-driven-3d-rotation/README.md@@ -1,7 +1,7 @@# Scroll-Driven 3D Rotation## What it is-Scroll-driven 3D rotation choreographs a 3D object's transforms — rotation, scale, position — against scroll progress through a pinned section. As the user scrolls, the object moves through a sequence of predetermined states. This is the pattern behind Apple's product reveal pages, where a product rotates, expands, and repositions as you scroll through marketing copy.+Scroll-driven 3D rotation ties an object's turn to the scroll position. The object stays pinned in view while the visitor scrolls through a tall section, and each stretch of scrolling moves it on to the next pose: turned, tilted, grown, then showing its back. Scrolling back runs it in reverse, the way many product pages show off a new device.## When to use it- Product reveal pages where each scroll stage highlights a different feature or angle@@ -21,6 +21,8 @@ Combine two techniques: **pin** (sticky positioning keeps the 3D stage visible w</div>```+In this demo the scrolling box is the stage itself: its content is four stage heights tall (400%) and the pinned frame is one stage height, a quarter of the content. On a whole page the same structure is a section of 400vh.+**Scroll progress → transform:**```jscontainer.addEventListener('scroll', () => {@@ -38,6 +40,8 @@ container.addEventListener('scroll', () => {function lerp(a, b, t) { return a + (b - a) * t; }```+The demo's keyframes are four poses, one for each quarter of the scroll: a quarter turn to the side, a forward tilt, a larger size (1.4 times), then turning round to show the back.+**Smooth scrub** adds a lerp each frame to ease between the raw scroll value and the applied rotation — this gives a cinematic feel:```js@@ -49,13 +53,13 @@ function animate() {}```+The demo asks for another frame only while the cube is still catching up, and stops once it has settled. The Turn amount setting multiplies the angles of every pose by 0.6, 1 or 1.6, and with reduced motion turned on the demo skips the gliding and sets each pose at once.+## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Section height | 400vh | Total scroll budget — taller = slower reveal, more reading time |-| Keyframe count | 4 | Number of distinct rotation stages in the sequence |-| Lerp factor | 0.1 | Smoothing per frame — 0.1 is cinematic, 1.0 is instant |-| CSS perspective | 600px | Lower = more dramatic 3D distortion |+| Turn amount | Normal | How far every pose turns the cube: less is 0.6, normal 1 and more 1.6 times the planned angles; at normal the last pose shows the cube's back |+| Smooth follow | on | The cube closes a tenth of the gap to its pose every frame, so it glides after the scroll; off, it follows the scroll exactly |## Production notes- **CSS Scroll-Driven Animations API** (Chrome 115+): `animation-timeline: scroll()` and `animation-range` can drive CSS transforms directly without JavaScript. The spec covers this natively, but browser support is still catching up for complex choreography.@@ -64,6 +68,6 @@ function animate() {- **Mobile scroll budget**: 400vh of scroll on mobile means the user must scroll a lot. Consider reducing section height for mobile, or switching to a swipe-driven (touch-drag) interaction.## See also-- [3D Model Orbit](../3d-model-orbit/) — WebGL-rendered version of the same concept-- [Scrub Animation](../../01-scroll-based/scrub-animation/) — general scroll-scrub pattern without 3D-- [Sticky Section](../../01-scroll-based/sticky-section/) — the pinning pattern that enables scroll-driven reveals+- [3D Model Orbit](../3d-model-orbit/) — time turns the object instead of scrolling+- [Scrub Animation](../../01-scroll-based/scrub-animation/) — scroll position drives any animation, without 3D+- [Sticky Section](../../01-scroll-based/sticky-section/) — the pinning that keeps the object in viewdiff --git a/animations/06-3d-advanced/scroll-driven-3d-rotation/index.html b/animations/06-3d-advanced/scroll-driven-3d-rotation/index.htmlindex 049cc6dd..efda574c 100644--- a/animations/06-3d-advanced/scroll-driven-3d-rotation/index.html+++ b/animations/06-3d-advanced/scroll-driven-3d-rotation/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Scroll-Driven 3D Rotation — Animation Handbook</title>- <meta name="description" content="Scroll progress choreographs 3D rotation through four stages — the Apple product-page pattern.">+ <meta name="description" content="Scrolling turns a 3D cube from pose to pose. Best for product tours."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/scroll-driven-3d-rotation/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,174 +12,166 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Scroll-Driven 3D Rotation — Animation Handbook">- <meta property="og:description" content="Scroll progress choreographs 3D rotation through four stages — the Apple product-page pattern.">+ <meta property="og:description" content="Scrolling turns a 3D cube from pose to pose. Best for product tours."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/scroll-driven-3d-rotation/"><meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png"><meta name="twitter:card" content="summary_large_image"><meta name="twitter:title" content="Scroll-Driven 3D Rotation — Animation Handbook">- <meta name="twitter:description" content="Scroll progress choreographs 3D rotation through four stages — the Apple product-page pattern.">+ <meta name="twitter:description" content="Scrolling turns a 3D cube from pose to pose. Best for product tours."><meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">- <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Scroll-Driven 3D Rotation", "name": "Scroll-Driven 3D Rotation", "description": "Scroll progress choreographs 3D rotation through four stages — the Apple product-page pattern.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/scroll-driven-3d-rotation/", "inLanguage": "en", "articleSection": "3D & Advanced", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, 3D & Advanced, Scroll-Driven 3D Rotation"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Scroll-Driven 3D Rotation", "name": "Scroll-Driven 3D Rotation", "description": "Scrolling turns a 3D cube from pose to pose. Best for product tours.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/06-3d-advanced/scroll-driven-3d-rotation/", "inLanguage": "en", "articleSection": "3D & Advanced", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, 3D & Advanced, Scroll-Driven 3D Rotation"}</script><style>- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-700.woff2') format('woff2');font-weight:700;font-display:swap}- @font-face{font-family:'Bricolage';src:url('../../../assets/fonts/brico-800.woff2') format('woff2');font-weight:800;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-400.woff2') format('woff2');font-weight:400;font-display:swap}- @font-face{font-family:'PlexMono';src:url('../../../assets/fonts/plex-500.woff2') format('woff2');font-weight:500;font-display:swap}- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#3fd6c4;--ui-text:#f4f4f2;--ui-muted:#77777e;--stage-h:620px;--disp:'Bricolage','Arial Narrow',sans-serif;--mono:'PlexMono',ui-monospace,Menlo,Consolas,monospace}+ :root{--ui-accent:#3fd6c4}*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}- body{background:var(--bg);color:var(--ui-text);font-family:var(--mono);-webkit-font-smoothing:antialiased;padding:clamp(12px,3vw,24px)}- header{margin-bottom:20px}- header h1{font-family:var(--disp);font-weight:700;font-size:clamp(11px,1.8vw,15px);letter-spacing:-.01em}- header p{font-size:clamp(10px,1.2vw,12px);color:var(--ui-muted);margin-top:4px}- .layout{display:flex;gap:clamp(12px,2vw,24px);align-items:flex-start}- .stage{flex:1;min-width:0;height:var(--stage-h);border:1px solid var(--ui-border);border-radius:8px;background:#04060c;overflow-y:auto;overflow-x:hidden;position:relative;scroll-behavior:auto}- /* Scroll container: 4× stage height gives scroll budget */- .scroll-content{height:calc(var(--stage-h)*4);position:relative}- .sticky-wrap{position:sticky;top:0;height:var(--stage-h);display:flex;align-items:stretch}+ /* The stage is the scroller: its content is four stage heights tall, and the frame that holds the cube stays pinned */+ .stage{background:#04060c;overflow-y:auto;overflow-x:hidden}+ .scroll-content{height:400%;position:relative;--cube:120px}+ /* The cube is 120px; on a stage under about 285px tall it shrinks with the stage, so its tilted, enlarged pose stays inside */+ @supports (height:1cqh){+ .stage{container-type:size}+ .scroll-content{--cube:min(120px,42cqh)}+ }+ .sticky-wrap{position:sticky;top:0;height:25%;display:flex;align-items:stretch}/* 3D display */.obj-panel{flex:1;display:flex;align-items:center;justify-content:center;perspective:600px}.obj-wrap{transform-style:preserve-3d;will-change:transform;transition:transform 0ms linear}/* CSS cube */- .cube{width:120px;height:120px;position:relative;transform-style:preserve-3d}- .face{position:absolute;width:120px;height:120px;border:2px solid rgba(88,166,255,.5);display:flex;align-items:center;justify-content:center;font-size:11px;color:rgba(88,166,255,.7);letter-spacing:1px}- .face.front{background:rgba(88,166,255,.08);transform:translateZ(60px)}- .face.back{background:rgba(88,166,255,.06);transform:rotateY(180deg) translateZ(60px)}- .face.left{background:rgba(88,166,255,.04);transform:rotateY(-90deg) translateZ(60px)}- .face.right{background:rgba(88,166,255,.04);transform:rotateY(90deg) translateZ(60px)}- .face.top{background:rgba(88,166,255,.03);transform:rotateX(90deg) translateZ(60px)}- .face.bottom{background:rgba(88,166,255,.03);transform:rotateX(-90deg) translateZ(60px)}- /* Info panel */- .info-panel{width:clamp(140px,30%,200px);display:flex;flex-direction:column;justify-content:center;gap:16px;padding:24px;border-left:1px solid var(--ui-border)}- .stage-label{font-size:9px;letter-spacing:2px;text-transform:uppercase;color:var(--ui-accent);opacity:.6}- .stage-val{font-size:clamp(16px,2.5vw,22px);font-weight:bold;color:#fff;font-variant-numeric:tabular-nums}- .stage-desc{font-size:10px;color:var(--ui-muted);line-height:1.5}- .chapter-dot{width:6px;height:6px;border-radius:50%;background:var(--ui-border);display:inline-block;margin-right:4px;transition:background .3s}- .chapter-dot.active{background:var(--ui-accent)}- /* Progress bar at top */- .prog-bar{position:absolute;top:0;left:0;right:0;height:2px;background:var(--ui-border);z-index:2}- .prog-fill{height:100%;background:var(--ui-accent);width:0%;transition:width 50ms linear}- /* Side panel */- aside{width:clamp(200px,22vw,240px);flex-shrink:0;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px;padding:16px;display:flex;flex-direction:column;gap:10px}- .note{font-size:10px;color:var(--ui-muted);line-height:1.6;border-left:2px solid var(--ui-accent);padding-left:8px}- .lbl{font-size:10px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-accent)}- .kv{display:flex;justify-content:space-between;font-size:10px;color:var(--ui-muted)}- .kv .v{color:var(--ui-text)}- .div{height:1px;background:var(--ui-border)}- .sr{display:flex;align-items:center;gap:6px;font-size:10px}- .sr input[type=range]{flex:1;accent-color:var(--ui-accent);min-height:44px}- .sv{width:40px;text-align:right;color:var(--ui-text)}- .tog{display:flex;align-items:center;gap:8px;font-size:10px;cursor:pointer;min-height:44px}- .tog input{accent-color:var(--ui-accent);width:16px;height:16px;flex-shrink:0}- button.rst{background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:var(--mono);font-size:10px;padding:14px 8px;min-height:44px;border-radius:4px;cursor:pointer;width:100%}- @media(hover:hover){button.rst:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}- @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none;width:100%}aside{width:100%}:root{--stage-h:480px}.info-panel{width:120px;padding:12px}}- @media(prefers-reduced-motion:reduce){.obj-wrap{transition:none!important}.prog-fill{transition:none!important}}+ .cube{width:var(--cube);height:var(--cube);position:relative;transform-style:preserve-3d}+ .face{position:absolute;width:var(--cube);height:var(--cube);border:2px solid rgba(88,166,255,.5);display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:600;color:rgba(88,166,255,.9);letter-spacing:1px}+ .face.front{background:rgba(88,166,255,.08);transform:translateZ(calc(var(--cube)/2))}+ .face.back{background:rgba(88,166,255,.06);transform:rotateY(180deg) translateZ(calc(var(--cube)/2))}+ .face.left{background:rgba(88,166,255,.04);transform:rotateY(-90deg) translateZ(calc(var(--cube)/2))}+ .face.right{background:rgba(88,166,255,.04);transform:rotateY(90deg) translateZ(calc(var(--cube)/2))}+ .face.top{background:rgba(88,166,255,.03);transform:rotateX(90deg) translateZ(calc(var(--cube)/2))}+ .face.bottom{background:rgba(88,166,255,.03);transform:rotateX(-90deg) translateZ(calc(var(--cube)/2))}+ @media(prefers-reduced-motion:reduce){.obj-wrap{transition:none!important}}</style>-<style id="ah-inject">-:root{--ah-bg:rgba(17,17,20,.82);--ah-line:rgba(255,255,255,.1);--ah-ink:#f4f4f2;--ah-muted:#9a9aa2;--ah-accent:#6ea8ff}-body{padding-top:46px}-.ah-bar{position:fixed;top:0;left:0;right:0;height:46px;z-index:2147483000;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:0 clamp(10px,3vw,18px);background:var(--ah-bg);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);border-bottom:1px solid var(--ah-line);font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12px;box-sizing:border-box}-.ah-bar a,.ah-bar button{color:var(--ah-muted);text-decoration:none;background:none;border:0;font:inherit;cursor:pointer;display:inline-flex;align-items:center;gap:6px;min-height:34px;padding:0 7px;border-radius:6px;transition:color .18s,background .18s;white-space:nowrap}-.ah-bar a:hover,.ah-bar button:hover{color:var(--ah-ink)}-.ah-home{color:var(--ah-ink);font-weight:600}-.ah-actions{display:flex;align-items:center;gap:2px}-.ah-sep{width:1px;height:16px;background:var(--ah-line);margin:0 4px}-.ah-copied{color:var(--ah-accent)!important}-@media(max-width:600px){.ah-bar .ah-hideSm{display:none}}-@media print{.ah-bar{display:none}body{padding-top:0}}-</style>+ <link rel="stylesheet" href="../../../assets/css/demo-page.css?v=4">+ <script src="../../../assets/js/demo-page.js?v=4" defer></script></head>-<body>-<div class="ah-bar" role="navigation" aria-label="Animation Handbook"><a class="ah-home" href="../../../">← Animation Handbook</a><span class="ah-actions"><a class="ah-hideSm" href="../3d-model-orbit/" rel="prev" title="Previous">‹ Prev</a><a class="ah-hideSm" href="../parallax-3d-tilt/" rel="next" title="Next">Next ›</a><span class="ah-sep ah-hideSm"></span><button type="button" id="ah-copy" class="ah-hideSm">Copy source</button><a class="ah-hideSm" href="https://github.com/matinmonshizadeh/animation-handbook/blob/main/animations/06-3d-advanced/scroll-driven-3d-rotation/index.html" target="_blank" rel="noopener noreferrer">Source ↗</a></span></div>-<header>- <h1>Scroll-Driven 3D Rotation</h1>- <p>Scroll progress choreographs 3D rotation through four stages — the Apple product-page pattern.</p>-</header>-<div class="layout">- <div class="stage" id="stage">- <div class="scroll-content">- <div class="sticky-wrap">- <div class="prog-bar"><div class="prog-fill" id="prog-fill"></div></div>- <div class="obj-panel">- <div class="obj-wrap" id="obj-wrap">- <div class="cube">- <div class="face front">FRONT</div>- <div class="face back">BACK</div>- <div class="face left">LEFT</div>- <div class="face right">RIGHT</div>- <div class="face top">TOP</div>- <div class="face bottom">BOT</div>+<body class="hb" data-hb-kind="scroll" data-hb-autoplay>+<nav class="hb-bar" aria-label="Animation Handbook">+ <a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>+ <span class="hb-pager"><a href="../3d-model-orbit/" rel="prev" aria-label="Previous: 3D Model Orbit"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>3D Model Orbit</span></a><a href="../parallax-3d-tilt/" rel="next" aria-label="Next: Parallax 3D Tilt"><span><span class="hb-dir">Next: </span>Parallax 3D Tilt</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>+</nav>+<main class="hb-page">+ <header class="hb-head">+ <p class="hb-cat">06.02 · 3D & Advanced</p>+ <h1>Scroll-Driven 3D Rotation</h1>+ <p class="hb-lede">Scrolling turns a 3D cube from pose to pose. Best for product tours.</p>+ </header>++ <section class="hb-step hb-watch" aria-labelledby="hb-watch-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">1</span>+ <div><h2 id="hb-watch-title">Scroll it</h2><p>Scroll inside the box, or press Play and it scrolls for you.</p></div>+ </div>+ <div class="stage hb-dots" id="stage" tabindex="0" role="region" aria-label="A cube that turns as you scroll this box">+ <div class="scroll-content">+ <div class="sticky-wrap">+ <div class="obj-panel">+ <div class="obj-wrap" id="obj-wrap" role="img" aria-label="A cube with its six faces labelled front, back, left, right, top and bottom">+ <div class="cube">+ <div class="face front">FRONT</div>+ <div class="face back">BACK</div>+ <div class="face left">LEFT</div>+ <div class="face right">RIGHT</div>+ <div class="face top">TOP</div>+ <div class="face bottom">BOTTOM</div>+ </div></div></div></div>- <div class="info-panel" id="info-panel">- <div>- <div class="stage-label">Progress</div>- <div class="stage-val" id="prog-val">0%</div>- </div>- <div>- <div class="stage-label">Chapter</div>- <div id="chapter-dots">- <span class="chapter-dot active"></span>- <span class="chapter-dot"></span>- <span class="chapter-dot"></span>- <span class="chapter-dot"></span>- </div>- </div>- <div>- <div class="stage-label">Stage</div>- <div class="stage-val" id="stage-name" style="font-size:clamp(12px,1.5vw,15px)">Start</div>- </div>- <div class="stage-desc" id="stage-desc">Scroll to animate the object through four states.</div>+ </div>+ </div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-scroll" data-hb-autoscroll><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M19 12l-7 7-7-7"/></svg>Play</button>+ <button class="hb-play" type="button" id="btn-top" data-hb-top><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 19V5M5 12l7-7 7 7"/></svg>Back to top</button>+ </div>+ </section>++ <section class="hb-step hb-try" aria-labelledby="hb-try-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">2</span>+ <div><h2 id="hb-try-title">Try it</h2><p>Change a setting, then scroll again or press Play.</p></div>+ </div>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="turn-lbl">Turn amount</p>+ <div class="seg" id="turn-seg" role="group" aria-labelledby="turn-lbl">+ <button type="button" data-mult="6" aria-pressed="false">Less</button>+ <button type="button" data-mult="10" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-mult="16" aria-pressed="false">More</button></div>+ <p class="hb-hint">How far each pose turns the cube.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Smooth follow</span><input class="hb-switch" type="checkbox" role="switch" id="smooth-tog" checked autocomplete="off"></label>+ <p class="hb-hint">The cube glides to catch up instead of jumping.</p></div></div>- </div>- <aside>- <p class="note">Pin (sticky) + scrub (scroll-progress) + 3D transforms = the Apple product reveal. Scroll budget is 3× stage height, giving time to read each stage.</p>- <div class="lbl">Scroll Progress</div>- <div class="sr" style="pointer-events:none"><input type="range" id="prog-sl" min="0" max="100" value="0" step="1" style="pointer-events:none"><span class="sv" id="prog-sl-v">0%</span></div>- <div class="lbl">Rotation Multiplier</div>- <div class="sr"><input type="range" id="mult-sl" min="5" max="30" value="10" step="1"><span class="sv" id="mult-v">1.0×</span></div>- <label class="tog"><input type="checkbox" id="smooth-tog" checked><span>Smooth scrub (lerp)</span></label>- <div class="div"></div>- <div class="kv"><span>Rotation X</span><span class="v" id="rx-v">0°</span></div>- <div class="kv"><span>Rotation Y</span><span class="v" id="ry-v">0°</span></div>- <div class="kv"><span>Scale</span><span class="v" id="sc-v">1.0</span></div>- <div class="div"></div>- <button class="rst" id="reset-btn">↺ Reset scroll</button>- </aside>-</div>+ </section>++ <section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">+ <div class="hb-step-head">+ <span class="hb-num" aria-hidden="true">3</span>+ <div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>+ </div>+ <div class="hb-card">+ <p class="hb-prompt">Add a scroll-driven 3D rotation to [the product or object you want to show]. Pin the object in view while the visitor scrolls through a tall section, and turn the scroll position, from the top of the section to its end, into a series of poses: turned to one side, tilted forward, larger, then turned round to show its back. Blend smoothly between neighbouring poses so scrolling back plays it in reverse, and when the settings include it, let the object glide to catch up instead of jumping with the scroll. If the visitor has reduced motion turned on, follow the scroll exactly, with no gliding. Match the settings listed below.</p>+ <div class="hb-chips-box" hidden>+ <p class="hb-chips-title">Your settings</p>+ <ul class="hb-chips"></ul>+ </div>+ <div class="hb-copy-row">+ <button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>+ <p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>+ </div>+ </div>+ </section>++ <section class="hb-about" aria-labelledby="hb-what-title">+ <div class="hb-what">+ <h2 id="hb-what-title">What it is</h2>+ <div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>+ </div>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Product tours</li><li>Device launches</li><li>Landing pages</li><li>Storytelling sections</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Short pages</li><li>Forms and dashboards</li></ul>+ </div>+ </section>++ <section class="hb-related" aria-labelledby="hb-related-title" hidden>+ <h2 id="hb-related-title">Similar animations</h2>+ <div class="hb-rel-list"></div>+ </section>+</main>+<footer class="hb-foot"><span>Animation Handbook</span><a href="#top">Back to top ↑</a></footer><script>const stageEl=document.getElementById('stage');const objWrap=document.getElementById('obj-wrap');-const progFill=document.getElementById('prog-fill');-const progVal=document.getElementById('prog-val');-const stageName=document.getElementById('stage-name');-const stageDesc=document.getElementById('stage-desc');-const dots=[...document.querySelectorAll('.chapter-dot')];+const smoothTog=document.getElementById('smooth-tog');let currRx=0,currRy=0,currSc=1,tgtRx=0,tgtRy=0,tgtSc=1,raf=null,mult=10;const reduceMotion=matchMedia('(prefers-reduced-motion: reduce)');-// Each chapter is the end state the object reaches by the end of that quarter of scroll+// Each pose is the state the cube reaches by the end of that quarter of the scrollconst START={rx:0,ry:0,sc:1};-const CHAPTERS=[- {name:'Orbit Y',desc:'Rotating 90° around the Y axis.',rx:0,ry:90,sc:1},- {name:'Tilt X',desc:'Tilting 30° forward on the X axis.',rx:-30,ry:90,sc:1},- {name:'Scale Up',desc:'Growing 1.4× while tilted.',rx:-30,ry:90,sc:1.4},- {name:'Back Face',desc:'Completing −180° Y rotation to show the back.',rx:0,ry:-180,sc:1},+const POSES=[+ {rx:0,ry:90,sc:1}, // a quarter turn to the side+ {rx:-30,ry:90,sc:1}, // tilted forward+ {rx:-30,ry:90,sc:1.4}, // larger+ {rx:0,ry:-180,sc:1}, // turned round to show its back];function lerp(a,b,t){return a+(b-a)*t}function render(){objWrap.style.transform=`rotateX(${currRx.toFixed(1)}deg) rotateY(${currRy.toFixed(1)}deg) scale(${currSc.toFixed(3)})`;- document.getElementById('rx-v').textContent=currRx.toFixed(0)+'°';- document.getElementById('ry-v').textContent=currRy.toFixed(0)+'°';- document.getElementById('sc-v').textContent=currSc.toFixed(2);}-// Smooth scrub: keep easing toward the target each frame until it settles, then stop the loop+// Smooth follow: keep easing toward the target each frame until it settles, then stop the loopfunction tick(){raf=null;currRx=lerp(currRx,tgtRx,.1);currRy=lerp(currRy,tgtRy,.1);currSc=lerp(currSc,tgtSc,.1);@@ -189,43 +181,35 @@ function tick(){function applyRotation(p){const cp=Math.min(Math.floor(p*4),3);const t=p*4-cp;- const c0=cp>0?CHAPTERS[cp-1]:START;const c1=CHAPTERS[cp];+ const c0=cp>0?POSES[cp-1]:START;const c1=POSES[cp];const k=mult/10;tgtRx=lerp(c0.rx,c1.rx,t)*k;tgtRy=lerp(c0.ry,c1.ry,t)*k;tgtSc=lerp(c0.sc,c1.sc,t);- const smooth=document.getElementById('smooth-tog').checked&&!reduceMotion.matches;+ const smooth=smoothTog.checked&&!reduceMotion.matches;if(smooth){if(!raf)raf=requestAnimationFrame(tick);}else{if(raf){cancelAnimationFrame(raf);raf=null;}currRx=tgtRx;currRy=tgtRy;currSc=tgtSc;render();}-- const chIdx=cp;- dots.forEach((d,i)=>d.classList.toggle('active',i===chIdx));- stageName.textContent=CHAPTERS[chIdx].name;- stageDesc.textContent=CHAPTERS[chIdx].desc;}function onScroll(){const {scrollTop,scrollHeight,clientHeight}=stageEl;const max=scrollHeight-clientHeight;- const p=max>0?scrollTop/max:0;- progFill.style.width=(p*100).toFixed(1)+'%';- progVal.textContent=Math.round(p*100)+'%';- document.getElementById('prog-sl').value=Math.round(p*100);- document.getElementById('prog-sl-v').textContent=Math.round(p*100)+'%';- applyRotation(p);+ applyRotation(max>0?scrollTop/max:0);}stageEl.addEventListener('scroll',onScroll,{passive:true});// Resizing changes scrollHeight/clientHeight without firing a scroll event,// so progress would stay frozen at its old value until the next scroll.new ResizeObserver(()=>{if(stageEl.scrollTop>0)onScroll();}).observe(stageEl);-document.getElementById('mult-sl').addEventListener('input',e=>{- mult=+e.target.value;document.getElementById('mult-v').textContent=(mult/10).toFixed(1)+'×';onScroll();-});-document.getElementById('smooth-tog').addEventListener('change',onScroll);-document.getElementById('reset-btn').addEventListener('click',()=>{- if(raf){cancelAnimationFrame(raf);raf=null;}- stageEl.scrollTop=0;currRx=currRy=0;currSc=1;applyRotation(0);render();-});++function choices(id,pick){+ const buttons=document.querySelectorAll('#'+id+' button');+ buttons.forEach(b=>b.addEventListener('click',()=>{+ buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});+ pick(b.dataset);+ }));+}+choices('turn-seg',d=>{mult=+d.mult;onScroll();});+smoothTog.addEventListener('change',onScroll);+onScroll();</script>-<script>(function(){var b=document.getElementById("ah-copy");if(!b)return;b.addEventListener("click",function(){fetch(location.href).then(function(r){return r.text();}).catch(function(){return document.documentElement.outerHTML;}).then(function(t){return navigator.clipboard.writeText(t);}).then(function(){b.textContent="Copied!";b.classList.add("ah-copied");setTimeout(function(){b.textContent="Copy source";b.classList.remove("ah-copied");},1500);}).catch(function(){b.textContent="Copy failed";setTimeout(function(){b.textContent="Copy source";},1500);});});})();</script></body></html>diff --git a/index.html b/index.htmlindex 5f421b3a..613d393a 100644--- a/index.html+++ b/index.html@@ -1009,7 +1009,7 @@ const CATS=[folder:'animations/06-3d-advanced',entries:[['3d-model-orbit','3D Model Orbit','A lit 3D shape spins, or turns to face your pointer. Best for product views.'],- ['scroll-driven-3d-rotation','Scroll-Driven 3D Rotation','CSS cube rotates through four choreographed stages as you scroll — the Apple product-page pattern.'],+ ['scroll-driven-3d-rotation','Scroll-Driven 3D Rotation','Scrolling turns a 3D cube from pose to pose. Best for product tours.'],['parallax-3d-tilt','Parallax 3D Tilt','CSS perspective + rotateX/Y follows mouse — a shine highlight tracks the virtual light source.'],['canvas-particle-effect','Canvas Particle Effect','Dots drift, link up when close, and dodge your pointer. Best for tech sites.'],['fluid-simulation','Fluid Simulation','Blobs drift and melt into each other like liquid. Best for hero backgrounds.'],