inflate
Letters puff up into round 3D shapes, like balloons or soft clay, that dent and wobble under the pointer.
Sweet Spot · candy bar and soda fountain
Sugar rush
Forty kinds of gummies, hand-pulled taffy and floats in six flavors. Open from noon, every day of the summer.
Live preview needs WebGPU or WebGL 2. A candy shop's summer headline in pink balloon letters on a pastel background, puffing up one letter after another.
This example failed to draw.
Usage
Put it on a heading, a label or the text inside a button, in a bold or display font. Not img, video, canvas, svg or form fields. start() registers inflate, so the attribute alone puts it on an element. The tabs below are the example above, with the values you set.
To change its code, copy the source into your effects folder; the copy replaces the built-in.
npx @dioramajs/diorama add inflate<section class="if-shop"> <p class="if-kicker">Sweet Spot · candy bar and soda fountain</p> <h2 class="if-title" data-dio="inflate">Sugar rush</h2> <p class="if-line">Forty kinds of gummies, hand-pulled taffy and floats in six flavors. Open from noon, every day of the summer.</p></section>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.if-title', 'inflate', { style: 'balloon', trigger: 'view', depth: 1, gloss: 0.7, squish: 1, tilt: 10,})import { start } from '@dioramajs/diorama'import inflate from '@dioramajs/text/inflate'
const app = start()app.attach('.if-title', inflate({ style: 'balloon', trigger: 'view', depth: 1, gloss: 0.7, squish: 1, tilt: 10,}))Page transitions
Leaving a page the letters go flat and fade; entering, they puff up again. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
stylerebuildsdata-dio-style | 'balloon' | 'soft' | 'jelly' | 'balloon' |
|
triggerrebuildsdata-dio-trigger | 'view' | 'hover' | 'always' | 'view' |
|
colorrebuildsdata-dio-color | string | '' | Color of the letters, any CSS color; empty keeps the color of each letter. |
depthdata-dio-depth | number0 to 2 | 1 | How far the letters puff out: 1 makes round tubes, 0 leaves them flat. |
glossdata-dio-gloss | number0 to 1.5 | 0.7 | Strength of the highlights and of the sheen at the rims; 0 for none. |
squishdata-dio-squish | number0 to 1.5 | 1 | How deep the pointer dents the letters under it; 0 turns the dent off. |
tiltdata-dio-tilt | number0 to 20° | 10 | Largest lean of the letters near the pointer, degrees; 0 keeps them upright. |
durationdata-dio-duration | number0 to 3 s | 1.1 | Time one letter takes to inflate, overshoot included. |
staggerdata-dio-stagger | number0 to 0.3 s | 0.06 | Delay between neighboring letters as they inflate. |
delaydata-dio-delay | number0 to 2 s | 0 | Wait after the trigger, for a cascade. |
thresholddata-dio-threshold | number0 to 1 | 0.3 | Share of the element height in view, above the bottom tenth, before it plays. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads delta, height, presence, reducedMotion, size, width, x and y
. Draws only while something on it moves, then stops. Full rate while letters inflate or deflate and while the dent and the lean follow the pointer and spring back; none at rest, under a still pointer or with the pointer away. How a frame is decided.
Reduced motion and touch
With reduced motion it shows a still frame: motion inputs are zero and time stands still. The letters are round from the start and stay still: no inflating, no dent and no lean, and no frames of their own. With trigger hover the label switches between flat and round without motion.
Runs on every device. A finger pressing the letters dents them and they spring back when it lifts; nothing follows a hover. With trigger hover a tap inflates the label and the next one lets it go flat.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { inflate: { reducedMotion: 'off' } } })Cost and quality
- Download
- 13.1 KB min+gzip the first time a page uses it
- GPU
- Two draws: a grid of about one vertex per 3 CSS px for each letter, raised in the vertex shader, with six texture reads per pixel for the light, and one quad for the shadow.
- Memory
- A canvas of the text at twice its CSS size with mip levels, and a half-float field of it with a margin for the shadow, 8 bytes a texel, built once on the CPU in short steps.
- Frames
- Idle at rest
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | The text is rastered at 1 device pixel per CSS pixel instead of 2, and its field holds at most 600,000 texels instead of 1.6 million. |
Recipes
Button labels that puff up on hover
With trigger="hover" the label stays plain text until the pointer or keyboard focus reaches the button, then its letters inflate in a quick wave and go flat again when it leaves; on a phone a tap inflates the label and the next tap lets it go. Put the effect on the text inside the button, not on the button: the effect draws the element it sits on in its place, so the button’s background, border and padding stay as they are. Shorter duration and stagger keep the wave quick.
Live preview needs WebGPU or WebGL 2. Two pill buttons on a cream background, Order a box and See flavors, whose labels inflate when hovered.
This example failed to draw.
<div class="if-cta"> <a class="if-button" href="/order"> <span data-dio="inflate" data-dio-trigger="hover" data-dio-duration="0.7" data-dio-stagger="0.03" >Order a box</span> </a> <a class="if-button if-ghost" href="/flavors"> <span data-dio="inflate" data-dio-trigger="hover" data-dio-style="soft" data-dio-duration="0.7" data-dio-stagger="0.03" >See flavors</span> </a></div>Matte clay for a craft studio
style="soft" turns the letters into matte clay: a broad soft light, no sharp highlight, and a darker seam where each letter meets the page. A lower gloss takes away the last of the sheen. It suits a wide, heavy font.
Mud Club
Wheel throwing for beginners · Tuesdays 6 to 8 p.m.
Live preview needs WebGPU or WebGL 2. A pottery class poster on a pale gray background with the name Mud Club in orange clay letters.
This example failed to draw.
<section class="if-studio"> <h2 class="if-name" data-dio="inflate" data-dio-style="soft" data-dio-gloss="0.5" >Mud Club</h2> <p class="if-when">Wheel throwing for beginners · Tuesdays 6 to 8 p.m.</p></section>Gummy candy in its own color
style="jelly" makes the letters translucent: clear and bright at the rims, deeper in color where they are thick, and the page shows through them. color overrides the text color for the letters and their shadow.
<h2 data-dio="inflate" data-dio-style="jelly" data-dio-color="#19b48a">Gummy bears</h2>Notes
The letters are built in 3D, not painted. A distance field of the glyphs is built once on the CPU, and the letters are inflated like a membrane under pressure, so straight strokes become round tubes, dots become domes and the joints of strokes bulge a little. Each letter is a mesh raised by that height and seen through the page camera, so it leans in perspective, and the normals of the surface take a studio light with a highlight and a soft shadow on the page. depth scales the height: 1 is round, larger is taller than wide.
The pointer dents the skin where it rests and deeper where it presses, the skin around the dent rises a little, and letters near it lean toward it. Everything springs back with a wobble when the pointer leaves or lets go. squish and tilt at 0 turn the dent and the lean off.
The text stays real text in the DOM: screen readers read it, search engines index it, and find in page works. While the letters are drawn the DOM text is hidden without being removed. With trigger="hover" the element is plain text at rest. Frames run only while letters inflate or go flat and while the dent and the lean move; at rest the effect draws nothing. Under reduced motion the letters are round from the start and do not move.
The effect looks best on bold or display fonts at 48 px and larger; hairlines of a thin serif inflate too, as fine glossy tubes. The canvas cannot draw background-clip: text, text-shadow, -webkit-text-stroke or vertical writing modes the way the browser does: an element with any of them keeps its text as it is, and a warning in development names the reason. style, trigger and color rebuild the effect when they change; the other params change live.