TransitionsPremium

Bubble Morph

A colored bubble forms, holds for a beat, then swells into a rounded square until it fills the screen; the page changes underneath and the shape runs the same path backwards. Two clearly readable beats in 1.5 s, a scale computed to cover any screen, CSS + 1.8 KB of JavaScript.

CSSJSMorphShape

Updated

This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Transitions has 52 effects, including 9 free. Explore the category →

3 usage examples

Round "New catch" button to entry form — a fishing club's logbook — Bubble Morph example 1

① Round "New catch" button to entry form — a fishing club's logbook

WhenBy the brook, a member has just landed a trout and taps the "+" at the bottom right of the logbook: the button seems to inflate, fills the screen, and leaves the "New catch" form ready to fill in.
WhyThe bubble starts from the finger: you understand where the new screen comes from, and on the way back it folds into the same spot. One-handed, no menu to hunt for.
Settings540 × 360 px screen with no rounding; 52 px bubble in the button's color, pinned on it with .mph-layer { align-items: flex-end; justify-content: flex-end; padding: 0 18px 16px 0 }; round .mph-btn laid over the screen. The cross that replaces the "+" is a scene style tied to the state. For the capture, the scene presses the button by itself.
Meeting room switching to "busy" — the tablet by the rooms' door — Bubble Morph example 2

② Meeting room switching to "busy" — the tablet by the rooms' door

WhenAt 10 am sharp, the site meeting starts in the Verrière room and the weekly stand-up ends in the Canopée room: on the hallway tablet, the first room's green dot swells in red over its whole tile, the second does the opposite in green.
WhyFour identical tiles: the status dot itself is what grows, so the eye goes straight to the room that just changed, and the color says which way.
SettingsFour 246 × 140 px .mph-stage elements; 14 px bubble placed top left (.mph-layer aligned on flex-start, padding: 16px), red or green depending on the tile; busy rooms start with mph-is-b written in the HTML. The buttons are hidden (hidden): in the capture, the scene calls their click() in place of the room calendar.
Sign-up confirmed for a beach clean-up — a coastal nonprofit's page — Bubble Morph example 3

③ Sign-up confirmed for a beach clean-up — a coastal nonprofit's page

WhenA resident reads Saturday's clean-up notice and presses "Sign me up": a lagoon-colored bubble inflates in the middle of the card, covers it, and withdraws on "You're in. See you Saturday!", with the counter gone from 23 to 24 sign-ups.
WhyThe card neither moves nor resizes, only its content is replaced: the bubble makes that replacement visible, where a plain text change would leave doubt that the click registered.
Settings236 × 252 px card, bubble brought down to 64 px in its original colors, full-width button under the card. The two button labels ("Sign me up", "Cancel my registration") are two <span> elements the scene shows depending on the state: the sold code does not change the button's text.

How it works

Inside the .mph-screen, a .mph-layer centers a single shape with flexbox, .mph-shape: a 100 px disc with a green gradient, shrunk to scale(0) at rest. Clicking .mph-btn starts the mphMorph animation in four quarters of 375 ms: the bubble appears and reaches its 100 px, swells to its maximum size while its rounding goes from 50% to 10%, comes back to the bubble, then goes out. Only two properties move, transform: scale() and border-radius: nothing is laid out again.

The ease-in-out curve applies to each quarter separately, so the shape slows to a stop when it has its bubble size, at 375 ms and at 1,125 ms. That held beat is what gives the feeling of a drop forming before it bursts. Read on a 568 × 200 px screen: 51 px at 190 ms, 100 px at 375 ms, 639 px at 560 ms, 1,204 px at 750 ms; the shape's box overlaps the whole screen from about 550 ms.

The maximum size is not fixed. On each click the script measures the screen and writes into --mph-cover the scale that gives the shape twice the screen's diagonal (12.04 for the screen above). That margin means it still covers it if you start it from a corner, or shrink it to a 14 px dot. The pages swap at 750 ms, at the peak, through the .mph-is-b class; at 1.5 s the button is handed back. A click in between is ignored, and every .mph-stage on the page runs independently of the others.

Accessibility

  • Reduced motion: a shape growing until it swallows the screen is among the movements to avoid for sensitive people. If prefers-reduced-motion is on at click time, the bubble does not form; the two pages cross in 150 ms of opacity (shape size kept at 0, page B set 60 ms after the click).
  • Color area: the screen is fully painted in the bubble's color for about 0.4 s, once per click, with no flicker. On a very large screen, prefer a tint close to the pages' over a bright red or white.
  • Keyboard: the control is a <button> (Enter, Space). It keeps focus during the transition, when it only carries aria-disabled="true". 2 px outline on keyboard focus, which fades in over 0.3 s because the button has a transition on all its properties.
  • Screen readers: the masked page is visibility: hidden and the shape's layer is aria-hidden, but the page change is silent. For a confirmation (sign-up, payment), put the message in a role="status" region.

Browser compatibility

CSS (@keyframes on scale() and border-radius, the --mph-cover variable read inside the keyframe, flexbox, inset) + 1.8 KB of JavaScript (Math.hypot, getBoundingClientRect, matchMedia). Everything is 2D: the three engines tested, Chromium 149, Firefox 151 and WebKit 26.5, give the same sizes at the same instants (100 px at 375 ms, 1,204 px at 750 ms) and the same end state. The floor comes from inset: Chrome 87, Firefox 66, Safari 14.1.

Chrome 87+✓ Full (measured in Chromium 149)
Firefox 66+✓ Full (measured in Firefox 151)
Safari 14.1+✓ Full (measured in WebKit 26.5)
Edge 87+✓ Full (Chromium engine)
Mobile iOS 14.5+✓ Not checked on a device
Android Chrome 87+✓ Full (emulated touch)

If the script does not run, nothing moves: page A stays on screen. If the --mph-cover variable is missing, the keyframe falls back to a scale of 20, enough for a screen whose diagonal stays under 1,000 px with the 100 px bubble.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="mph-stage">
  <div class="mph-screen">
    <div class="mph-page mph-page-a">…</div>
    <div class="mph-page mph-page-b">…</div>
    <div class="mph-layer" aria-hidden="true">
      <div class="mph-shape"></div>
    </div>
  </div>
  <button type="button" class="mph-btn">…</button>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Bubble color (CSS — .mph-shape { background }) #047857 → #0e7490 gradient The same shape is used both ways. Take the color of the triggering button if the bubble should seem to come out of it, or a status color (red, green) for a tile.
Bubble size (CSS — .mph-shape { width; height }) 100 px It is the size of the held beat. The script reads the shape's real width to compute the scale: from 14 px to 100 px, nothing else to change.
Starting point (CSS — align-items, justify-content and padding on .mph-layer) center of the screen flex-end on both axes starts it from the bottom right corner, flex-start from the top left; the padding sets the gap to the edge. The screen stays covered at the peak.
Rounding at the peak (CSS — border-radius: 10% at 50% of @keyframes mphMorph) 10% 0 gives a sharp rectangle, 50% keeps a circle from start to finish: the morph is gone, only a growth remains.
Duration (CSS — animation: mphMorph 1.5s; JS — SWAP_AT, END_AT) 1.5 s; swap at 750 ms, end at 1,500 ms Keep SWAP_AT at half the duration and END_AT equal to it. At 0.9 s the effect becomes a mere pulse; past 2 s the wait is felt.

FAQ

Zoom Through enlarges in one stroke a dark layer the size of the screen (scale(0) to scale(3)) and holds it for two tenths of a second: a centered dive into black, in 1.2 s. Bubble Morph works in two beats with a small colored shape: it forms, stops at its bubble size, then swells by a scale computed from the screen. So you can start it from a button or a dot, which Zoom Through's full-frame layer does not allow.
Because the animation has one keyframe at 25% and another at 75%, where the shape is exactly scale(1), and ease-in-out restarts from zero at every keyframe. For a swell in a single stroke, delete the 25%, 75% block from @keyframes mphMorph: the shape will go from 0 to its maximum size with no pause, and the result will come close to Zoom Through.
No. The --mph-cover scale is measured at each click, not at load: after a phone rotation or a window resize, the next transition covers the new screen. Only a transition already running keeps the scale computed when it started, for 1.5 s at most.