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: Dynamic Island (04.41): the cards' content sits inside the clipped shape, so it never shows outside it

matinae8a485e020d
diff --git a/animations/04-micro-interactions/dynamic-island/README.md b/animations/04-micro-interactions/dynamic-island/README.md
index a3b2167f..38aae44b 100644
--- a/animations/04-micro-interactions/dynamic-island/README.md
+++ b/animations/04-micro-interactions/dynamic-island/README.md
@@ -11,12 +11,13 @@ A Dynamic Island is a small black pill at the top of a phone screen that grows i
- Live scores and other short updates worth a glance
## How it works
-The island is a box the size of its largest card, with a little room left around it for the bounce. Everything inside is laid out once at full size; what the visitor sees is a black layer cut out with `clip-path: inset()`. Three custom properties describe the visible shape: half its width (`--hw`), its height (`--h`) and its corner radius (`--r`). Changing them is the whole animation: the browser eases the clip from one shape to the other, so the pill grows into a card, or one card changes straight into another, without ever animating `width` or `height`.
+The island is a box the size of its largest card, with a little room left around it for the bounce. Everything inside is laid out once at full size; what the visitor sees is a black layer cut out with `clip-path: inset()`, and each card's content sits inside that layer, so the same clip cuts the content too and nothing shows outside the shape while it grows or shrinks. Three custom properties describe the visible shape: half its width (`--hw`), its height (`--h`) and its corner radius (`--r`). Changing them is the whole animation: the browser eases the clip from one shape to the other, so the pill grows into a card, or one card changes straight into another, without ever animating `width` or `height`.
```html
<button class="isl" type="button" aria-label="Phone notification" aria-expanded="false" data-n="call">
- <span class="shape"></span> <!-- the black layer, clipped -->
- <span class="c c-call" aria-hidden="true">…</span> <!-- each card's content, at full size -->
+ <span class="shape"> <!-- the black layer, clipped -->
+ <span class="c c-call" aria-hidden="true">…</span> <!-- each card's content, at full size, clipped with it -->
+ </span>
</button>
```
@@ -57,7 +58,7 @@ function spring(z) {
}
```
-The same transition runs whichever two shapes it goes between, so picking another notification while one is open morphs the card directly. The clip also decides where the button can be pressed, so the small pill gets a larger invisible target (124 × 48px), and the focus ring is a second clipped layer 3px larger than the shape, behind it, because an outline would be clipped away. While a card is open the status bar fades out, and a polite live region reads out the message when the visitor opened it, not when Show me did. On larger screens the content also comes into focus from a slight blur; phones skip the blur. Under reduced motion a resting pill stays in place and the card fades in over it at its own size, so nothing grows or moves.
+The same transition runs whichever two shapes it goes between, so picking another notification while one is open morphs the card directly. The clip also decides where the button can be pressed, so the small pill gets a larger invisible target (124 × 48px). The button is the whole box, so its own outline would not follow the shape: the focus ring is a second clipped layer 3px larger than the shape, behind it, and the outline stays, transparent, for forced-colors mode. While a card is open the status bar fades out, and a polite live region reads out the message when the visitor opened it, not when Show me did. On larger screens the content also comes into focus from a slight blur; phones skip the blur. Under reduced motion a resting pill stays in place and the card fades in over it at its own size, so nothing grows or moves; picking another notification fades the open card out, puts the new content and size in place while it is hidden, and fades it in again.
## Key parameters
| Parameter | Default | Effect |
@@ -69,11 +70,12 @@ The same transition runs whichever two shapes it goes between, so picking anothe
## Production notes
- **Never animate `width` or `height`**: every frame would lay out the card and its text again, and the words would wrap and jump while it grows. A clip, or a scale on a layer whose children are scaled back, changes only what is painted.
- **A clip is repainted**: a `clip-path` animation repaints the island on every frame. That is cheap for a shape this size; for a large panel, animate `transform: scale()` on the layer and scale its content the other way (the FLIP technique), which stays on the compositor.
+- **Clip the content with the shape**: put the content inside the clipped layer, not beside it. A shrinking clip outruns a fade, so content laid over the shape shows on the page around it for a moment at the start of every close.
- **Leave room for the bounce**: a spring goes past the target size, and a clip cannot show more than its box. Make the box larger than the largest card by the overshoot, or the corners turn square for a moment at the peak.
-- **`linear()` support**: the spring curve needs `linear()` (Chrome and Edge 113, Firefox 112, Safari 17.2). Check with `CSS.supports()` and fall back to a `cubic-bezier()` that overshoots, such as `cubic-bezier(.3, 1.5, .45, 1)`.
-- **Hit area and focus**: the clip also clips pointer hits and the outline. Give the small pill a target of at least 44 × 44px, and draw the focus ring as a clipped layer of its own.
+- **`linear()` support**: the spring curve needs `linear()` (Chrome and Edge 113, Firefox 112, Safari 17.2). Check with `CSS.supports()` and fall back to a `cubic-bezier()` that overshoots about as far: `cubic-bezier(.3, 1.4, .5, 1)` goes about 5% past the end and `cubic-bezier(.3, 1.75, .45, 1)` about 16%.
+- **Hit area and focus**: the clip also clips pointer hits. Give the small pill a target of at least 44 × 44px, draw the focus ring as a clipped layer of its own, and keep a transparent outline for forced-colors mode.
- **Accessibility**: make the pill a real `<button>` with `aria-expanded`, announce a new message in a polite `role="status"` region, never move the focus into the card, and let Escape close it.
-- **Framer Motion**: `<motion.div layout style={{ borderRadius: 30 }} />` animates a size change with transforms and corrects the corner radius and the children's scale for you.
+- **Framer Motion**: `<motion.div layout style={{ borderRadius: 30 }} />` animates a size change with transforms and keeps the corner radius right; give the children `layout` too, so they are scaled back and their text does not stretch.
- **GSAP**: the Flip plugin records the pill's box and animates to the card's; `gsap.to(shape, { clipPath: "inset(0% 6% 14% 6% round 30px)", ease: "elastic.out(1, 0.6)" })` animates the clip itself with a bounce.
- **Native apps**: on iOS the real Dynamic Island shows Live Activities through ActivityKit; on the web it is a pattern you draw yourself.
diff --git a/animations/04-micro-interactions/dynamic-island/index.html b/animations/04-micro-interactions/dynamic-island/index.html
index 358e1980..c1aec171 100644
--- a/animations/04-micro-interactions/dynamic-island/index.html
+++ b/animations/04-micro-interactions/dynamic-island/index.html
@@ -33,19 +33,18 @@
.isl.open~.sb{opacity:0}.sb svg{width:58px;height:11px;fill:#fff}
.date,.clock{position:absolute;left:0;right:0;text-align:center}.date{top:188px;font-size:15px;font-weight:600;color:rgba(255,255,255,.88)}
.clock{top:206px;font-size:clamp(50px,19cqw,80px);font-weight:700;line-height:1;letter-spacing:-.02em}
- /* The island: a box the size of the largest card plus room for a bounce. Only its clipped black shape shows; the script sets
- --hw, --h and --r (half its width, its height and its corner radius) for the pill and for each card */
- .isl{--hw:48px;--h:32px;--r:16px;--dur:700ms;--ease:cubic-bezier(.3,1.2,.5,1);position:absolute;z-index:1;top:11px;left:6px;right:6px;height:172px;container-type:inline-size;border:0;background:none;color:#fff;font:inherit;text-align:left;
+ /* The island: a box the size of the largest card plus room for a bounce. Only its black shape shows, clipped, with the cards' content
+ inside it, so the clip cuts the content too. The script sets --hw, --h and --r (half width, height, corner radius) for each shape */
+ .isl{--hw:48px;--h:32px;--r:16px;--dur:700ms;--ease:cubic-bezier(.3,1.4,.5,1);position:absolute;z-index:1;top:11px;left:6px;right:6px;height:172px;container-type:inline-size;border:0;background:none;color:#fff;font:inherit;text-align:left;
cursor:pointer;pointer-events:none;-webkit-tap-highlight-color:transparent;transform-origin:50% calc(var(--h) / 2);transition:transform .25s cubic-bezier(.22,1,.36,1)}
.shape,.ring,.pill{position:absolute;inset:0;transition:clip-path var(--dur) var(--ease)}
- .shape{background:#000;pointer-events:auto;clip-path:inset(0 calc(50% - var(--hw)) calc(100% - var(--h)) round var(--r))}
- .isl:not(.open) .shape{pointer-events:none}
+ .shape{background:#000;pointer-events:auto;clip-path:inset(0 calc(50% - var(--hw)) calc(100% - var(--h)) round var(--r))}.isl:not(.open) .shape{pointer-events:none}
/* The pill is short, so a larger invisible target covers it at rest */
.hit{position:absolute;left:50%;top:-8px;width:124px;height:48px;margin-left:-62px;pointer-events:auto}
- /* Focus: an outline would be clipped away, so a ring layer 3px larger than the shape sits behind it (its box starts 3px higher) */
+ /* Focus: the button is the whole box, so its outline would not follow the shape. A ring layer 3px larger than the shape sits
+ behind it (its box starts 3px higher); the outline stays, transparent, for forced-colors mode, which drops the ring's color. */
.ring{top:-3px;opacity:0;background:var(--ui-accent);clip-path:inset(0 calc(50% - var(--hw) - 3px) calc(100% - var(--h) - 6px) round calc(var(--r) + 3px))}
- .isl:focus-visible .ring{opacity:1}
- .hb-page .stage .isl:focus-visible{outline:none}
+ .isl:focus-visible .ring{opacity:1}.hb-page .stage .isl:focus-visible{outline:2px solid transparent}
.pill{display:none;inset:0 auto auto 50%;width:96px;height:32px;margin-left:-48px;border-radius:16px;background:#000}
/* A pointer over the pill swells it a little, and a press squeezes the island, as a finger does on a phone */
@media(hover:hover) and (prefers-reduced-motion:no-preference){.isl:not(.open):hover{transform:scale(1.06)}}
@@ -56,17 +55,12 @@
transition:opacity calc(var(--dur) * .25) ease,transform var(--dur) var(--ease),filter calc(var(--dur) * .25) ease}
.open[data-n=call] .c-call,.open[data-n=timer] .c-timer,.open[data-n=music] .c-music{opacity:1;transform:none;filter:none;
transition-duration:calc(var(--dur) * .45),var(--dur),calc(var(--dur) * .45);transition-delay:calc(var(--dur) * .2)}
- .c-call{height:76px}.c-timer{left:10%;right:10%;height:64px;padding:0 min(12px,4cqw)}
- .c-music{height:148px;flex-direction:column;align-items:stretch;justify-content:center;gap:12px;padding:0 min(18px,5.5cqw)}
+ .c-call{height:76px}.c-timer{left:10%;right:10%;height:64px;padding:0 min(12px,4cqw)}.c-music{height:148px;flex-direction:column;align-items:stretch;justify-content:center;gap:12px;padding:0 min(18px,5.5cqw)}
.tx{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px;white-space:nowrap}
- .tx small{font-size:min(12px,4.6cqw);color:var(--muted)}
- .tx b{font-size:clamp(13px,5.6cqw,16px);font-weight:600;overflow:hidden;text-overflow:ellipsis}
+ .tx small{font-size:min(12px,4.6cqw);color:var(--muted)}.tx b{font-size:clamp(13px,5.6cqw,16px);font-weight:600;overflow:hidden;text-overflow:ellipsis}
.av{position:relative;flex:none;display:grid;place-items:center;width:min(42px,14cqw);aspect-ratio:1;border-radius:50%;background:linear-gradient(135deg,#c2410c,#9d174d);font-size:min(15px,5cqw);font-weight:700}
- .av i{position:absolute;inset:-4px;border:2px solid #ff8a65;border-radius:50%;opacity:0}
- .open[data-n=call] .av i{animation:ringing 1.6s ease-out infinite}
- @keyframes ringing{0%{transform:scale(.92);opacity:.9}100%{transform:scale(1.4);opacity:0}}
- .rb{flex:none;display:grid;place-items:center;width:min(36px,12.5cqw);aspect-ratio:1;border-radius:50%}
- .rb svg{width:50%;height:50%;fill:none;stroke:#fff;stroke-width:2.4;stroke-linecap:round}
+ .av i{position:absolute;inset:-4px;border:2px solid #ff8a65;border-radius:50%;opacity:0}.open[data-n=call] .av i{animation:ringing 1.6s ease-out infinite}@keyframes ringing{0%{transform:scale(.92);opacity:.9}100%{transform:scale(1.4);opacity:0}}
+ .rb{flex:none;display:grid;place-items:center;width:min(36px,12.5cqw);aspect-ratio:1;border-radius:50%}.rb svg{width:50%;height:50%;fill:none;stroke:#fff;stroke-width:2.4;stroke-linecap:round}
.no{background:#ff453a}.no svg{transform:rotate(135deg)}.yes{background:#30d158}.no svg,.yes svg{fill:#fff;stroke:none}
.pz{background:rgba(255,159,10,.24)}.pz svg{stroke:var(--orange)}.x{background:#3a3a3c}
.c-timer .tx{align-items:flex-end;color:var(--orange)}.c-timer .tx small{color:inherit}
@@ -74,21 +68,20 @@
.c-timer .tx b{font-size:min(30px,10cqw);line-height:1}.c-timer .tx b i{display:inline-block;width:.62em;text-align:center;font-style:normal}
.mrow{display:flex;align-items:center;gap:min(12px,3.5cqw)}
.art{flex:none;width:min(48px,16cqw);aspect-ratio:1;border-radius:12px;background:radial-gradient(circle at 32% 30%,#ffd36e 0 16%,transparent 17%),linear-gradient(140deg,#ff7a59,#c2185b 55%,#5b2a86)}
- .wave{flex:none;display:flex;align-items:center;gap:3px;height:22px}
- .wave i{width:3px;height:100%;border-radius:2px;background:#ff8a65;transform:scaleY(.35)}
- .open[data-n=music] .wave i{animation:wave .8s ease-in-out var(--d,0s) infinite alternate}
+ .wave{flex:none;display:flex;align-items:center;gap:3px;height:22px}.wave i{width:3px;height:100%;border-radius:2px;background:#ff8a65;transform:scaleY(.35)}
+ .open[data-n=music] .wave i{animation:wave .8s ease-in-out var(--d,0s) infinite alternate}@keyframes wave{to{transform:scaleY(1)}}
.wave i:nth-child(2){--d:-.5s}.wave i:nth-child(3){--d:-.2s}.wave i:nth-child(4){--d:-.65s}
- @keyframes wave{to{transform:scaleY(1)}}
- .prog{display:flex;align-items:center;gap:8px;font-size:11px;color:var(--muted)}
- .prog i{flex:1;height:4px;border-radius:2px;background:linear-gradient(90deg,#fff 34%,#3a3a3c 34%)}
+ .prog{display:flex;align-items:center;gap:8px;font-size:11px;color:var(--muted)}.prog i{flex:1;height:4px;border-radius:2px;background:linear-gradient(90deg,#fff 34%,#3a3a3c 34%)}
.mctl{display:flex;justify-content:center;gap:30px}.mctl svg{width:24px;height:24px;fill:#fff}
- .still,.still *{transition:none!important}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
+ .isl.still,.isl.still *{transition:none!important}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
/* Larger screens: the content comes into focus as it fades in (a phone skips the blur) */
@media(min-width:601px) and (min-height:501px){.c{filter:blur(6px)}}
- /* Reduced motion: a resting pill shows, and the card fades in over it and out again at its own size; nothing grows or moves */
+ /* Forced colors: the phone keeps its own colors (a black pill on black would vanish); the button's outline is still forced */
+ @media(forced-colors:active){.screen,.shape,.pill{forced-color-adjust:none}.isl{forced-color-adjust:auto}}
+ /* Reduced motion: a resting pill shows; a card fades in over it and out at its own size (a new one after the open one fades out) */
@media(prefers-reduced-motion:reduce){
.isl,.shape,.ring,.c{transition:opacity .3s ease!important}
- .pill{display:block}.shape{opacity:0}.open .shape{opacity:1}.c{transform:none;filter:none}
+ .pill{display:block}.shape,.isl.swap .shape{opacity:0}.open .shape{opacity:1}.c{transform:none;filter:none}
.isl:not(.open):focus-visible .ring{opacity:0}.isl:not(.open):focus-visible .pill{box-shadow:0 0 0 3px var(--ui-accent)}
.open[data-n] .av i,.open[data-n] .wave i{animation:none}
}
@@ -119,14 +112,14 @@
<p class="date" aria-hidden="true">Thursday, October 1</p>
<p class="clock" aria-hidden="true">9:41</p>
<button class="isl" id="isl" type="button" aria-label="Phone notification" aria-expanded="false" data-n="call">
- <span class="ring"></span><span class="pill"></span><span class="shape"></span><span class="hit"></span>
- <span class="c c-call" aria-hidden="true"><span class="av">MC<i></i></span><span class="tx"><small>Incoming call</small><b>Maya Chen</b></span>
+ <span class="ring"></span><span class="pill"></span><span class="hit"></span>
+ <span class="shape"><span class="c c-call" aria-hidden="true"><span class="av">MC<i></i></span><span class="tx"><small>Incoming call</small><b>Maya Chen</b></span>
<span class="rb no"><svg viewBox="0 0 24 24"><path d="M20 15.5c-1.25 0-2.45-.2-3.57-.57a1 1 0 0 0-1.02.24l-2.2 2.2a15 15 0 0 1-6.59-6.59l2.2-2.21a1 1 0 0 0 .25-1A11.4 11.4 0 0 1 8.5 4a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1c0 9.39 7.61 17 17 17a1 1 0 0 0 1-1v-3.5a1 1 0 0 0-1-1z"/></svg></span><span class="rb yes"><svg viewBox="0 0 24 24"><path d="M20 15.5c-1.25 0-2.45-.2-3.57-.57a1 1 0 0 0-1.02.24l-2.2 2.2a15 15 0 0 1-6.59-6.59l2.2-2.21a1 1 0 0 0 .25-1A11.4 11.4 0 0 1 8.5 4a1 1 0 0 0-1-1H4a1 1 0 0 0-1 1c0 9.39 7.61 17 17 17a1 1 0 0 0 1-1v-3.5a1 1 0 0 0-1-1z"/></svg></span></span>
<span class="c c-timer" aria-hidden="true"><span class="rb pz"><svg viewBox="0 0 24 24"><path d="M9 7v10M15 7v10"/></svg></span><span class="rb x"><svg viewBox="0 0 24 24"><path d="m7.5 7.5 9 9m0-9-9 9"/></svg></span>
<span class="tx"><small>Timer</small><b id="tm"><i>5</i>:<i>0</i><i>0</i></b></span></span>
<span class="c c-music" aria-hidden="true"><span class="mrow"><span class="art"></span><span class="tx"><b>Golden Hour</b><small>Nova Lane</small></span><span class="wave"><i></i><i></i><i></i><i></i></span></span>
<span class="prog">1:12<i></i>-2:31</span>
- <span class="mctl"><svg viewBox="0 0 24 24"><path d="M6 6h2v12H6zm3.5 6 8.5 6V6z"/></svg><svg viewBox="0 0 24 24"><path d="M6 5h4v14H6zm8 0h4v14h-4z"/></svg><svg viewBox="0 0 24 24"><path d="m6 18 8.5-6L6 6zM16 6v12h2V6z"/></svg></span></span>
+ <span class="mctl"><svg viewBox="0 0 24 24"><path d="M6 6h2v12H6zm3.5 6 8.5 6V6z"/></svg><svg viewBox="0 0 24 24"><path d="M6 5h4v14H6zm8 0h4v14h-4z"/></svg><svg viewBox="0 0 24 24"><path d="m6 18 8.5-6L6 6zM16 6v12h2V6z"/></svg></span></span></span>
</button>
<div class="sb" aria-hidden="true"><span>9:41</span><svg viewBox="0 0 58 11"><rect y="7" width="3" height="4" rx="1"/><rect x="4.5" y="5" width="3" height="6" rx="1"/><rect x="9" y="2.5" width="3" height="8.5" rx="1"/><rect x="13.5" width="3" height="11" rx="1"/><path d="M27 11l-2-2.2a3 3 0 0 1 4 0zm-3.4-3.6-1.4-1.5a6.6 6.6 0 0 1 9.6 0l-1.4 1.5a4.6 4.6 0 0 0-6.8 0zm-2.8-2.9L19.4 3a10.6 10.6 0 0 1 15.2 0l-1.4 1.5a8.6 8.6 0 0 0-12.4 0z"/><rect x="37.5" y=".5" width="18" height="10" rx="3" fill="none" stroke="#fff" stroke-opacity=".5"/><rect x="39.5" y="2.5" width="11" height="6" rx="1.5"/></svg></div>
</div>
@@ -182,7 +175,7 @@
<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 Dynamic Island style notification to [the top of your app or page]. At rest it is a small black pill; when [an event such as an incoming message] happens or the pill is pressed, it grows into a rounded card with the details, then shrinks back. Change the black shape with a clip or a scale, never by animating its width or height, so the text inside never stretches and nothing around it moves, and fade the details in only once the shape has room for them. Make the pill a real button for taps, clicks and the keyboard, and announce its message politely to screen readers. If the visitor has reduced motion turned on, crossfade the pill and the card instead. Match the settings listed below.</p>
+ <p class="hb-prompt">Add a Dynamic Island style notification to [the top of your app or page]. At rest it is a small black pill; when [an event such as an incoming message] happens or the pill is pressed, it grows into a rounded card with the details, then shrinks back. Change the black shape with a clip or a scale, never by animating its width or height, so the text inside never stretches and nothing around it moves. Keep the details inside the shape, fading them in once it has room. Make the pill a real button for taps, clicks and the keyboard, and announce its message politely to screen readers. If the visitor has reduced motion turned on, crossfade the pill and the card instead. 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>
@@ -221,7 +214,7 @@
// of the widest card and room below the tallest, so a bounce past the card's size is never cut off by the box.
const SIZE={rest:['48px','32px','16px'],call:['44%','76px','30px'],timer:['40%','64px','32px'],music:['44%','148px','34px']};
const SAY={call:'Incoming call from Maya Chen.',timer:'Timer: 5 minutes left.',music:'Now playing: Golden Hour by Nova Lane.'};
- let note='call',open=false,dur=700,runTimers=[],tick=0;
+ let note='call',open=false,dur=700,runTimers=[],tick=0,swap=0;
// Bounce: a damped spring (damping z, 1 = no overshoot) sampled into a CSS linear() curve that settles by its end. Soft overshoots
// the size by about 5%, Springy by about 16%. Browsers without linear() get a cubic-bezier that overshoots about as far.
@@ -231,7 +224,7 @@
return 'linear('+p.join(',')+',1)';
}
const curves=CSS.supports('transition-timing-function','linear(0,1)');
- const EASE={none:'cubic-bezier(.22,1,.36,1)',soft:curves?spring(.68):'cubic-bezier(.3,1.2,.5,1)',springy:curves?spring(.5):'cubic-bezier(.3,1.5,.45,1)'};
+ const EASE={none:'cubic-bezier(.22,1,.36,1)',soft:curves?spring(.68):'cubic-bezier(.3,1.4,.5,1)',springy:curves?spring(.5):'cubic-bezier(.3,1.75,.45,1)'};
// The shape's size: the open card's, else the resting pill's. Under reduced motion the card keeps its size while it fades out.
function shape(){
@@ -246,9 +239,9 @@
const draw=()=>{const s=Math.max(0,300-Math.floor((performance.now()-t0)/1000));tm.innerHTML=(Math.floor(s/60)+':'+String(s%60).padStart(2,'0')).replace(/\d/g,'<i>$&</i>')};
draw();tick=setInterval(draw,250);
}
- // Open or close it. Only the visitor's own changes are announced (politely); Show me's are not.
+ // Open or close it, calling off a card switch still waiting. Only the visitor's own changes are announced (politely), not Show me's.
function setOpen(next,visitor){
- open=next;isl.classList.toggle('open',open);isl.setAttribute('aria-expanded',String(open));
+ clearTimeout(swap);isl.classList.remove('swap');open=next;isl.classList.toggle('open',open);isl.setAttribute('aria-expanded',String(open));
shape();clock();
if(visitor)say.textContent=open?SAY[note]:'';
}
@@ -288,8 +281,15 @@
pick(b.dataset);
}));
}
- // A new notification opens the island, or changes the open card's shape into the new one
- choices('note-seg',d=>{note=d.n;isl.dataset.n=note;stopRun();setOpen(true,true)});
+ // A new notification opens the island, or changes the open card's shape into the new one. Under reduced motion the open card
+ // fades out first (swap); hidden, it takes the new content and size without a transition, then fades in again.
+ choices('note-seg',d=>{
+ const show=()=>{note=d.n;isl.dataset.n=note;setOpen(true,true)};
+ stopRun();clearTimeout(swap);
+ if(!open||!reduceMq.matches||d.n===note)return show();
+ isl.classList.add('swap');
+ swap=setTimeout(()=>{isl.classList.add('still');note=d.n;isl.dataset.n=note;shape();void isl.offsetWidth;isl.classList.remove('still');show()},300);
+ });
choices('speed-seg',d=>{dur=+d.ms;isl.style.setProperty('--dur',dur+'ms')});
choices('bounce-seg',d=>isl.style.setProperty('--ease',EASE[d.b]));
isl.style.setProperty('--ease',EASE.soft);shape();