melt
Letters melt like wet paint, candle wax or liquid metal, running down in glossy drips that stretch, neck and let their drops fall.
Summer sale · ends Sunday at midnight
Up to 40% off linen shirts, sandals and everything else that keeps you cool. Free shipping on orders over $60.
Heatwave
Live preview needs WebGPU or WebGL 2. A summer sale banner on a dark page whose orange headline Heatwave melts into glossy paint drips under the pointer.
This example failed to draw.
Usage
Put it on a large heading, a logo word or a short label in a bold font, with room below it for the drips. Not img, video, canvas, svg or form fields. start() registers melt, 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 melt<section class="mt-sale"> <p class="mt-kicker">Summer sale · ends Sunday at midnight</p> <p class="mt-line">Up to 40% off linen shirts, sandals and everything else that keeps you cool. Free shipping on orders over $60.</p> <h2 class="mt-title" data-dio="melt">Heatwave</h2></section>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.mt-title', 'melt', { style: 'drip', trigger: 'hover', strength: 1, speed: 1, gloss: 1,})import { start } from '@dioramajs/diorama'import melt from '@dioramajs/text/melt'
const app = start()app.attach('.mt-title', melt({ style: 'drip', trigger: 'hover', strength: 1, speed: 1, gloss: 1,}))Page transitions
The liquid fades with the page. 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 | 'drip' | 'wax' | 'chrome' | 'drip' |
|
triggerrebuildsdata-dio-trigger | 'hover' | 'scroll' | 'view' | 'loop' | 'hover' |
|
strengthdata-dio-strength | number0 to 2 | 1 | How far the letters sag and the drips run; 0 keeps the shape and drips none. |
dripsrebuildsdata-dio-drips | number0 to 40 | 12 | Number of drips across the text, spread along the undersides of the letters.At most low 8 by quality tier. |
speeddata-dio-speed | number0 to 3 | 1 | Pace of the melt, of setting again after a hover and of the loop. |
glossdata-dio-gloss | number0 to 2 | 1 | Strength of the highlights and the reflections; 0 is matte. |
colorrebuildsdata-dio-color | string | '' | Color of the liquid, any CSS color; empty uses the color of the text. |
seedrebuildsdata-dio-seed | number1 to 100 | 1 | Picks where the drips hang and how long each one runs. |
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, reducedMotion, size, width, x and y
. Draws at a steady rate while it is on screen and stops when it leaves. With trigger hover and scroll the text is plain DOM at rest with no frames: full rate while it melts or sets under the pointer, one frame per scroll. View draws at full rate while it melts, then holds its look with none. Loop draws 30 frames a second while in view and none off screen. 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. Hover and scroll leave the text as it is. View and loop show the melted look, drips hanging, without motion.
Runs on every device. With trigger hover a tap melts the spot under the finger, which sets again after a moment. Scroll, view and loop work the same as with a mouse.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { melt: { reducedMotion: 'off' } } })Cost and quality
- Download
- 13.4 KB min+gzip the first time a page uses it
- GPU
- One quad over the text and the room below it; per pixel six evaluations of the shape, each a texture read or two and a loop over the drips near it.
- Memory
- A canvas of the text and a half-float distance field of it and of its rounded shape, at most 900,000 texels, built once on the CPU; a small heat map for the hover.
- Frames
- Draws while on screen
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | At most 8 drips, and the text is rastered at 1 device pixel per CSS pixel instead of 2. |
Recipes
Ice cream that drips once as it shows
trigger="view" melts the heading once, the first time it comes into view, and keeps the melted look: the drips stay hanging and nothing more is drawn. A few more drips than the default suit a short, wide word. Leave room under the heading, since the drips run up to about two lines of its size below it, and keep other text to the side.
Two Scoops · Harbor Street, open till 11
Soft serve
Live preview needs WebGPU or WebGL 2. An ice cream parlor menu on a cream page, the pink title Soft serve dripping beside a list of four flavors with prices.
This example failed to draw.
<section class="mt-parlor"> <div class="mt-head"> <p class="mt-where">Two Scoops · Harbor Street, open till 11</p> <h2 class="mt-scoop" data-dio="melt" data-dio-trigger="view" data-dio-drips="16" >Soft serve</h2> </div> <ul class="mt-menu"> <li>Vanilla bean <span>$4</span></li> <li>Strawberry swirl <span>$4.5</span></li> <li>Salted caramel <span>$5</span></li> <li>Pistachio <span>$5</span></li> </ul></section>Liquid chrome on a loop
style="chrome" turns the letters into rippling mercury that mirrors a small studio, and trigger="loop" keeps it dripping: each drip grows, lets its drop fall and pulls back, at 30 frames a second while it is on screen and none off screen. It suits a title on a dark page, such as a music release or a launch.
Halcyon Tapes · new album, out March 14
Quicksilver
Live preview needs WebGPU or WebGL 2. An album announcement on a dark page with the title Quicksilver in liquid chrome that drips and ripples.
This example failed to draw.
<section class="mt-album"> <p class="mt-label">Halcyon Tapes · new album, out March 14</p> <h2 class="mt-name" data-dio="melt" data-dio-style="chrome" data-dio-trigger="loop" data-dio-drips="10" >Quicksilver</h2></section>A candle that slumps as the page scrolls
style="wax" softens the letters into warm, translucent wax that sinks toward the baseline and pools under them, with a few short, thick drips. With trigger="scroll" it follows the page both ways: solid as the heading enters, fully melted as it nears the top of the viewport, and solid again when the page scrolls back. A heading on screen when the page opens starts solid where it is.
<h2 data-dio="melt" data-dio-style="wax" data-dio-trigger="scroll">Slow burn</h2>Notes
The shape of the liquid comes from a distance field of the text: every pixel knows how far it is from the nearest edge of a letter. The shader samples that field at shifted positions to make the letters sag, blends it toward a rounded copy of the text, and joins it smoothly with the drips, so edges stay smooth at every stage of the melt. The same distance gives the liquid a round edge for the light: highlights along the rims, reflections of a small studio that move with the page, and a soft shadow on the page below.
Drips hang from the undersides of the letters near the baseline: feet of stems, bottoms of bowls and descenders. seed picks where they hang and how long they run, and drips sets how many there are. strength scales how far the letters sink and how long the drips get; at 0 the letters keep their shape and only turn glossy.
With trigger hover and scroll the heading is plain DOM text at rest and draws no frames: it turns liquid only while melted. With view and loop the liquid copy stands in for the text, which stays in the DOM, hidden, so screen readers, search and find in page still work. With hover, keyboard focus melts the whole label and a tap on a touch screen melts the spot under the finger.
Use a bold, large font: thin strokes leave little for the liquid to round off, and small counters fill as the letters soften. The canvas cannot draw background-clip: text, text-shadow, -webkit-text-stroke or vertical writing modes the way the browser does, and an element with any of them keeps its text as it is, with a warning in development.
style, trigger, color, drips and seed rebuild the effect when they change; strength, speed and gloss change live.