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 Flip In to the guided-steps page
matin8abd8bd9884a
diff --git a/animations/02-entrance-and-exit/flip-in/README.md b/animations/02-entrance-and-exit/flip-in/README.mdindex de01ca5c..ff4690bb 100644--- a/animations/02-entrance-and-exit/flip-in/README.md+++ b/animations/02-entrance-and-exit/flip-in/README.md@@ -23,7 +23,7 @@ The stage sets `perspective`, establishing a shared vanishing point for its chil.card.in{opacity:1;transform:rotateY(0deg) rotateX(0deg)}```-The axis controls decide which rotation carries the starting angle — Y for a horizontal hinge, X for a vertical one, or both for a corner flip:+The Swing direction setting decides which rotation carries the starting angle: Sideways uses rotateY (an upright hinge, like a door), Up and down uses rotateX (a flat hinge, like a flap) and Diagonal uses both:```jsconst ry=axis==='X'?'0deg':rot+'deg';@@ -32,19 +32,19 @@ document.documentElement.style.setProperty('--rot-y',ry);document.documentElement.style.setProperty('--rot-x',rx);```-`transform-origin` moves the hinge to an edge (top, bottom, left) so the card swings from that side rather than pivoting around its center.+The Hinge setting moves transform-origin to an edge (top, bottom, left) so the card swings from that side rather than pivoting around its center.## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|-| Flip axis | Y (horiz) | Which way it swings: around a vertical hinge, a horizontal one, or both |-| Starting rotation | 90° | The angle it starts from; 90° starts fully edge-on |-| Perspective | 1000px | How far away the viewer seems; lower is more dramatic, higher is subtler |-| Duration | 600ms | How long the swing takes; a Springy curve adds a satisfying settle |-| Easing | Ease out | Slows the swing as it comes to face you |-| Transform origin | Center | Where the hinge sits; an edge makes it swing from that side |-| Combine with fade | on | Fades it in while it turns |+| Swing direction | Sideways | Which way it swings: sideways around an upright hinge like a door, up and down like a flap, or diagonally |+| Hinge | Center | Where it turns from; an edge makes it swing from that side |+| Speed | Normal | How long the swing takes: slow is 1000ms, normal 600ms and fast 350ms |+| How far it turns | ¼ turn | The angle it starts from: a little (45°), a quarter turn (90°, edge-on) or half a turn (180°, facing away) |+| 3D depth | Medium | How close the viewer seems: subtle is 2000px, medium 1000px and strong 400px; closer is more dramatic |+| Feel | Smooth | Smooth slows the swing as it comes to face you; Springy adds a settle; Gentle eases in and out; Even keeps one steady pace |+| Fades in | on | Fades it in while it turns |## Production notes- **Perspective belongs on the parent**: this is the single most common mistake. Setting `perspective` on the card itself (via `transform: perspective(...)`) applies per-element and won't share a vanishing point across siblings; the container `perspective` property is what creates a coherent 3D scene.@@ -55,6 +55,6 @@ document.documentElement.style.setProperty('--rot-x',rx);- **GSAP**: set `transformPerspective` (or `perspective` on the container) and tween `rotationY`; GSAP's 3D handling is built in.## See also-- [Scale In](../scale-in/) — a flatter, 2D entrance for the same card slot-- [Rotate In](../rotate-in/) — 2D spin rather than a 3D hinge-- [Blur In](../blur-in/) — a non-spatial focal entrance alternative+- [Scale In](../scale-in/) — grows into place, flat on the page+- [Rotate In](../rotate-in/) — spins flat instead of turning in 3D+- [Blur In](../blur-in/) — sharpens from a blur as it fades indiff --git a/animations/02-entrance-and-exit/flip-in/index.html b/animations/02-entrance-and-exit/flip-in/index.htmlindex 067b21d9..a9776c49 100644--- a/animations/02-entrance-and-exit/flip-in/index.html+++ b/animations/02-entrance-and-exit/flip-in/index.html@@ -4,7 +4,7 @@<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Flip In — Animation Handbook</title>- <meta name="description" content="Rotates from a flat plane into view using CSS 3D perspective — perspective on the parent is the key.">+ <meta name="description" content="Swings into view in 3D, like a card turning over. Best for cards and tiles."><link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/flip-in/"><link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png"><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">@@ -12,23 +12,18 @@<meta property="og:type" content="article"><meta property="og:site_name" content="Animation Handbook"><meta property="og:title" content="Flip In — Animation Handbook">- <meta property="og:description" content="Rotates from a flat plane into view using CSS 3D perspective — perspective on the parent is the key.">+ <meta property="og:description" content="Swings into view in 3D, like a card turning over. Best for cards and tiles."><meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/flip-in/"><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="Flip In — Animation Handbook">- <meta name="twitter:description" content="Rotates from a flat plane into view using CSS 3D perspective — perspective on the parent is the key.">+ <meta name="twitter:description" content="Swings into view in 3D, like a card turning over. Best for cards and tiles."><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": "Flip In", "name": "Flip In", "description": "Rotates from a flat plane into view using CSS 3D perspective — perspective on the parent is the key.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/flip-in/", "inLanguage": "en", "articleSection": "Entrance & Exit", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Entrance & Exit, Flip In"}</script>+ <script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Flip In", "name": "Flip In", "description": "Swings into view in 3D, like a card turning over. Best for cards and tiles.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/02-entrance-and-exit/flip-in/", "inLanguage": "en", "articleSection": "Entrance & Exit", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Entrance & Exit, Flip In"}</script><style>- :root{--bg:#0b0b0d;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-accent:#5fd88a;--ui-text:#f4f4f2;--ui-muted:#77777e;--stage-h:620px;--dur:600ms;--ease:ease-out;--persp:1000px;--rot-y:90deg;--rot-x:0deg;--origin:center}+ :root{--ui-accent:#5fd88a;--ui-muted:#77777e;--dur:600ms;--ease:ease-out;--persp:1000px;--rot-y:90deg;--rot-x:0deg;--origin:center}*,*::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(16px,2.2vw,22px);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:var(--bg);display:flex;align-items:center;justify-content:center;overflow:hidden;perspective:var(--persp)}+ .stage{display:flex;align-items:center;justify-content:center;background:#0b0b0d;perspective:var(--persp)}.card{background:#161b22;border:1px solid #30363d;border-radius:14px;padding:clamp(28px,5vw,48px);text-align:center;width:clamp(220px,50%,280px);opacity:0;transform:rotateY(var(--rot-y)) rotateX(var(--rot-x));transform-origin:var(--origin);transition:transform var(--dur) var(--ease),opacity var(--dur) var(--ease);will-change:transform,opacity}@@ -37,148 +32,209 @@.card-title{font-size:clamp(16px,2.4vw,21px);font-weight:bold;margin-bottom:8px}.card-sub{font-size:11px;color:var(--ui-muted);line-height:1.65}@media(prefers-reduced-motion:reduce){.card{transition:opacity 300ms linear!important;transform:none!important}}- 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:42px;text-align:right;color:var(--ui-text)}- select{background:var(--ui-bg);border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:8px 6px;border-radius:4px;width:100%;min-height:44px}- .seg{display:flex;gap:3px;flex-wrap:wrap}- .seg button{flex:1;background:none;border:1px solid var(--ui-border);color:var(--ui-muted);font-family:monospace;font-size:9px;padding:8px 4px;border-radius:4px;cursor:pointer;min-height:44px}- .seg button.on{border-color:var(--ui-accent);color:var(--ui-accent);background:rgba(95,216,138,.12)}- .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}- .btn-row{display:flex;gap:6px}- button.act{flex:1;background:transparent;border:1px solid var(--ui-border);color:var(--ui-text);font-family:monospace;font-size:10px;padding:14px 6px;border-radius:4px;cursor:pointer;min-height:44px}- button.act.pri{border-color:var(--ui-accent);color:var(--ui-accent)}- @media(hover:hover){button.act:hover{border-color:var(--ui-accent);color:var(--ui-accent)}}- @media(max-width:600px){.layout{flex-direction:column}.stage{flex:none}aside{width:100%}:root{--stage-h:480px}}</style>-<link rel="stylesheet" href="../../../assets/css/handbook.css">-<script src="../../../assets/js/handbook.js" defer></script>+ <link rel="stylesheet" href="../../../assets/css/demo-page.css">+ <script src="../../../assets/js/demo-page.js" defer></script></head>-<body class="hb" data-hb-autoplay>-<nav class="hb-bar" aria-label="Animation Handbook"><a class="hb-home" href="../../../">← <span>Animation Handbook</span></a><span class="hb-pager"><a href="../blur-in/" rel="prev" aria-label="Previous: Blur In">‹ <span class="hb-name">Blur In</span></a><a href="../bounce-in/" rel="next" aria-label="Next: Bounce In"><span class="hb-name">Bounce In</span> ›</a></span></nav>-<main class="hb-view">- <div class="stage" id="stage">- <div class="card" id="card">- <div class="card-icon">⬡</div>- <div class="card-title">3D Flip</div>- <div class="card-sub">Perspective is set on the parent, not the card. Without it, rotateY looks like a horizontal squash — not a 3D rotation.</div>+<body class="hb" data-hb-kind="once" 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="../blur-in/" rel="prev" aria-label="Previous: Blur In"><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>Blur In</span></a><a href="../bounce-in/" rel="next" aria-label="Next: Bounce In"><span><span class="hb-dir">Next: </span>Bounce In</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">02.11 · Entrance & Exit</p>+ <h1>Flip In</h1>+ <p class="hb-lede">Swings into view in 3D, like a card turning over. Best for cards and tiles.</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">Watch it</h2><p>It plays by itself. Turn on slow motion to see each part of the movement.</p></div></div>- </div>- <aside class="hb-side">- <header class="hb-head">- <p class="hb-cat">02.11 · Entrance & Exit</p>- <h1>Flip In</h1>- <p class="hb-lede">Swings into view in 3D, like a hinged card turning toward you.</p>- </header>- <section class="hb-settings" aria-label="Settings">- <h2 class="hb-label">Settings</h2>- <div class="lbl">State</div>- <div class="kv"><span>Status</span><span class="v" id="st">hidden</span></div>- <div class="kv"><span>Rotation</span><span class="v" id="rot-val">Y: 90°</span></div>- <div class="div"></div>- <div class="lbl">Flip axis</div>- <div class="seg" id="axis-seg">- <button data-ax="Y" class="on">Y (horiz)</button>- <button data-ax="X">X (vert)</button>- <button data-ax="both">Both</button>+ <div class="stage hb-dots">+ <div class="card" id="card">+ <div class="card-icon">⬡</div>+ <div class="card-title">3D Flip</div>+ <div class="card-sub">The depth comes from the space around the card. Without it, the turn looks like a flat squash.</div>+ </div></div>- <div><div class="lbl" id="rot-lbl">Starting rotation</div>- <div class="sr"><input type="range" id="rot-sl" aria-labelledby="rot-lbl" min="45" max="180" value="90" step="5"><span class="sv" id="rot-v">90°</span></div>+ <div class="hb-player">+ <button class="hb-play" type="button" id="btn-play" data-hb-replay><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>Replay</button>+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="loop-tog" data-hb-loop><span>Loop</span></label>+ <label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo><span>Slow motion</span></label></div>- <div><div class="lbl" id="persp-lbl">Perspective</div>- <div class="sr"><input type="range" id="persp-sl" aria-labelledby="persp-lbl" min="200" max="2000" value="1000" step="100"><span class="sv" id="persp-v">1000px</span></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 and the animation plays again.</p></div></div>- <div><div class="lbl" id="dur-lbl">Duration</div>- <div class="sr"><input type="range" id="dur-sl" aria-labelledby="dur-lbl" min="100" max="2000" value="600" step="50"><span class="sv" id="dur-v">600ms</span></div>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="axis-lbl">Swing direction</p>+ <div class="seg" id="axis-seg" role="group" aria-labelledby="axis-lbl">+ <button type="button" data-axis="Y" class="on" aria-pressed="true">Sideways</button>+ <button type="button" data-axis="X" aria-pressed="false">Up and down</button>+ <button type="button" data-axis="both" aria-pressed="false">Diagonal</button>+ </div>+ <p class="hb-hint">Sideways turns like a door, up and down like a flap.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="origin-lbl">Hinge</p>+ <div class="seg" id="origin-seg" role="group" aria-labelledby="origin-lbl">+ <button type="button" data-o="center" class="on" aria-pressed="true">Center</button>+ <button type="button" data-o="top center" aria-pressed="false">Top</button>+ <button type="button" data-o="bottom center" aria-pressed="false">Bottom</button>+ <button type="button" data-o="left center" aria-pressed="false">Left</button>+ </div>+ <p class="hb-hint">An edge hinge makes it swing from that side.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="speed-lbl">Speed</p>+ <div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">+ <button type="button" data-ms="1000" aria-pressed="false">Slow</button>+ <button type="button" data-ms="600" class="on" aria-pressed="true">Normal</button>+ <button type="button" data-ms="350" aria-pressed="false">Fast</button>+ </div>+ <p class="hb-hint">Slow is easy to follow. Fast feels snappy.</p>+ </div></div>- <div><div class="lbl">Easing</div>- <select id="ease-sel">- <option value="linear">Linear</option>- <option value="ease-out" selected>Ease out</option>- <option value="ease-in-out">Ease in-out</option>- <option value="cubic-bezier(.2,.7,.3,1)">Smooth</option>- <option value="cubic-bezier(.34,1.56,.64,1)">Springy</option>- </select>+ <details class="hb-options">+ <summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>+ <div class="hb-settings">+ <div class="hb-setting">+ <p class="hb-setting-name" id="rot-lbl">How far it turns</p>+ <div class="seg" id="rot-seg" role="group" aria-labelledby="rot-lbl">+ <button type="button" data-rot="45" aria-pressed="false">A little</button>+ <button type="button" data-rot="90" class="on" aria-pressed="true">¼ turn</button>+ <button type="button" data-rot="180" aria-pressed="false">½ turn</button>+ </div>+ <p class="hb-hint">¼ turn starts edge-on; ½ turn starts facing away.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="persp-lbl">3D depth</p>+ <div class="seg" id="persp-seg" role="group" aria-labelledby="persp-lbl">+ <button type="button" data-persp="2000px" aria-pressed="false">Subtle</button>+ <button type="button" data-persp="1000px" class="on" aria-pressed="true">Medium</button>+ <button type="button" data-persp="400px" aria-pressed="false">Strong</button>+ </div>+ <p class="hb-hint">Strong looks closer and more dramatic.</p>+ </div>+ <div class="hb-setting">+ <p class="hb-setting-name" id="feel-lbl">Feel</p>+ <div class="seg" id="feel-seg" role="group" aria-labelledby="feel-lbl">+ <button type="button" data-ease="ease-out" class="on" aria-pressed="true">Smooth</button>+ <button type="button" data-ease="cubic-bezier(.34,1.56,.64,1)" aria-pressed="false">Springy</button>+ <button type="button" data-ease="ease-in-out" aria-pressed="false">Gentle</button>+ <button type="button" data-ease="linear" aria-pressed="false">Even</button>+ </div>+ <p class="hb-hint">Springy swings a little past, then settles.</p>+ </div>+ <div class="hb-setting">+ <label class="hb-switch-row"><span>Fades in</span><input class="hb-switch" type="checkbox" role="switch" id="fade-tog" checked></label>+ <p class="hb-hint">Softens the first moment.</p>+ </div>+ </div>+ </details>+ </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="lbl">Transform origin</div>- <div class="seg" id="orig-seg">- <button data-o="center" class="on">Center</button>- <button data-o="top center">Top</button>- <button data-o="bottom center">Bottom</button>- <button data-o="left center">Left</button>+ <div class="hb-card">+ <p class="hb-prompt">Add a 3D flip-in entrance to [the card you want to animate]. The card should start turned away from the viewer and swing toward them until it faces them flat. Give the card's container a 3D perspective so the swing has real depth; without it, the flip looks like a flat squash. The hinge can sit in the middle or along one edge, and the card can fade in while it turns. If the visitor has reduced motion turned on, show the card facing forward without the flip. 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>- <label class="tog" for="fade-tog"><input type="checkbox" id="fade-tog" checked><span>Combine with fade</span></label>- <div class="div"></div>- <label class="tog" for="loop-tog"><input type="checkbox" id="loop-tog" data-hb-skip data-hb-loop><span>Auto-loop</span></label>- <div class="btn-row">- <button class="act pri" id="btn-in" data-hb-replay aria-label="Play flip in">Play in</button>- <button class="act" id="btn-out" aria-label="Play flip out">Play out</button>- <button class="act" id="btn-rst" data-hb-reset aria-label="Reset">Reset</button>+ </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>- </section>- <div class="hb-take">- <section class="hb-prompt-box" aria-labelledby="hb-prompt-title">- <h2 class="hb-label" id="hb-prompt-title">Prompt</h2>- <p class="hb-prompt">Add a 3D flip-in entrance to [the card you want to animate]. The card should start turned edge-on, like a door seen from the side, and swing toward the viewer until it faces them flat. Give the card's container a 3D perspective so the swing has real depth; without it, the flip looks like a flat squash. The hinge can sit in the middle or along one edge, and the card can fade in while it turns. If the visitor has reduced motion turned on, show the card facing forward without the flip. Match the settings listed below.</p>- </section>+ <div class="hb-fit">+ <h2>Good for</h2>+ <ul class="hb-tags hb-good"><li>Cards</li><li>Flashcards and tiles</li><li>Dashboard panels</li><li>Onboarding steps</li></ul>+ <h3>Avoid on</h3>+ <ul class="hb-tags hb-avoid"><li>Text blocks</li><li>Full-page sections</li></ul></div>- </aside>+ </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 card=document.getElementById('card'),stage=document.getElementById('stage');- const stEl=document.getElementById('st'),rotVal=document.getElementById('rot-val');- const durSl=document.getElementById('dur-sl'),durV=document.getElementById('dur-v');- const rotSl=document.getElementById('rot-sl'),rotV=document.getElementById('rot-v');- const perspSl=document.getElementById('persp-sl'),perspV=document.getElementById('persp-v');- const easeSel=document.getElementById('ease-sel'),fadeTog=document.getElementById('fade-tog'),loopTog=document.getElementById('loop-tog');+ const card=document.getElementById('card');+ const vars=document.documentElement.style;+ const loopTog=document.getElementById('loop-tog'),slowTog=document.getElementById('slow-tog');+ const fadeTog=document.getElementById('fade-tog');const motionOk=!window.matchMedia('(prefers-reduced-motion:reduce)').matches;- let dur=600,axis='Y',rot=90,looping=false,loopTimer=null,animTimer=null;+ let axis='Y',origin='center',ms=600,rot=90,persp='1000px',ease='ease-out',timers=[];- function applyRot(){+ function dur(){return slowTog.checked?ms*3:ms}+ function apply(){const ry=axis==='X'?'0deg':rot+'deg';const rx=axis==='Y'?'0deg':rot+'deg';- document.documentElement.style.setProperty('--rot-y',ry);- document.documentElement.style.setProperty('--rot-x',rx);- rotVal.textContent=axis==='both'?`X/Y: ${rot}°`:axis+`: ${rot}°`;+ vars.setProperty('--rot-y',ry);+ vars.setProperty('--rot-x',rx);+ vars.setProperty('--origin',origin);+ vars.setProperty('--dur',dur()+'ms');+ vars.setProperty('--ease',ease);+ vars.setProperty('--persp',persp);+ card.style.opacity=fadeTog.checked?'':'1';+ }+ function later(fn,wait){timers.push(setTimeout(fn,wait))}+ function flipIn(){+ // snap back to the starting pose without a transition so every play starts from the beginning+ card.style.setProperty('transition','none','important');card.classList.remove('in');void card.offsetWidth;- if(!looping){clearTimeout(animTimer);stEl.textContent='hidden'}- if(!fadeTog.checked)card.style.opacity='1';else card.style.opacity='';+ card.style.removeProperty('transition');+ card.classList.add('in');}-- function _trigger(cls){- clearTimeout(animTimer);card.classList.remove('in');void card.offsetWidth;- if(cls==='in')card.classList.add('in');- stEl.textContent=cls==='in'?'playing in':'playing out';- animTimer=setTimeout(()=>stEl.textContent=cls==='in'?'visible':'hidden',dur);+ // One play flips in. While Loop is on it then holds, flips out, waits and plays again;+ // switching Loop off lets the card finish facing forward. Slow motion stretches the flips, not the waits.+ function cycle(){+ apply();flipIn();+ if(!loopTog.checked||!motionOk)return;+ later(()=>{+ if(!loopTog.checked)return;+ card.classList.remove('in');+ later(cycle,dur()+400);+ },dur()+800);}- function stopLoop(){looping=false;clearTimeout(loopTimer);loopTog.checked=false}- function loop(){_trigger('in');loopTimer=setTimeout(()=>{_trigger('out');loopTimer=setTimeout(()=>{if(looping)loop()},dur+400)},dur+800)}+ function play(){timers.forEach(clearTimeout);timers=[];cycle()}- document.getElementById('btn-in').addEventListener('click',()=>{stopLoop();_trigger('in')});- document.getElementById('btn-out').addEventListener('click',()=>{stopLoop();_trigger('out')});- document.getElementById('btn-rst').addEventListener('click',()=>{stopLoop();clearTimeout(animTimer);card.classList.remove('in');stEl.textContent='hidden'});- loopTog.addEventListener('change',()=>{looping=loopTog.checked;if(looping&&motionOk)loop();else stopLoop()});- document.querySelectorAll('#axis-seg button').forEach(b=>b.addEventListener('click',()=>{- document.querySelectorAll('#axis-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');- axis=b.dataset.ax;applyRot();stEl.textContent='hidden';- }));- document.querySelectorAll('#orig-seg button').forEach(b=>b.addEventListener('click',()=>{- document.querySelectorAll('#orig-seg button').forEach(x=>x.classList.remove('on'));b.classList.add('on');- document.documentElement.style.setProperty('--origin',b.dataset.o);- }));- rotSl.addEventListener('input',()=>{rot=+rotSl.value;rotV.textContent=rot+'°';applyRot()});- perspSl.addEventListener('input',()=>{const v=perspSl.value+'px';perspV.textContent=v;document.documentElement.style.setProperty('--persp',v);stage.style.perspective=v});- durSl.addEventListener('input',()=>{dur=+durSl.value;durV.textContent=dur+'ms';document.documentElement.style.setProperty('--dur',dur+'ms')});- easeSel.addEventListener('change',()=>document.documentElement.style.setProperty('--ease',easeSel.value));- fadeTog.addEventListener('change',()=>{card.style.opacity=fadeTog.checked?'':'1'});- applyRot();+ document.getElementById('btn-play').addEventListener('click',play);+ loopTog.addEventListener('change',()=>{if(loopTog.checked)play()});+ 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('axis-seg',d=>{axis=d.axis});+ choices('origin-seg',d=>{origin=d.o});+ choices('speed-seg',d=>{ms=+d.ms});+ choices('rot-seg',d=>{rot=+d.rot});+ choices('persp-seg',d=>{persp=d.persp});+ choices('feel-seg',d=>{ease=d.ease});+ apply();</script></body></html>diff --git a/index.html b/index.htmlindex 56491534..4d539da9 100644--- a/index.html+++ b/index.html@@ -922,7 +922,7 @@ const CATS=[['letter-by-letter-stagger','Letter-by-Letter Stagger','A phrase appears letter by letter, or is typed out. Best for short headlines.'],['word-by-word-reveal','Word-by-Word Reveal','Words appear one after another at a reading pace. Best for quotes and intros.'],['blur-in','Blur In','Comes into focus from a blur, like a camera. Best for featured cards and photos.'],- ['flip-in','Flip In','Rotates from a flat plane into view using CSS 3D perspective — perspective on the parent is the key.'],+ ['flip-in','Flip In','Swings into view in 3D, like a card turning over. Best for cards and tiles.'],['bounce-in','Bounce In','Overshoots final position then springs back — explicit @keyframes waypoints, not easing alone.'],['rotate-in','Rotate In','Spins into place while it grows. Best for icons, stars and badges.'],]