# melt

Letters melt like wet paint, candle wax or liquid metal, running down in glossy drips that stretch, neck and let their drops fall.

The shape of each letter turns liquid: its corners round off, its top sinks a little and its foot spreads, while drips run from the undersides of the strokes, widen into a bulb and now and then let a drop go that falls away below the text. The liquid is lit as a 3D surface with a round edge: sharp highlights along the rims, reflections of a small photo studio that slide as the page scrolls, and a soft shadow on the page. Drip is glossy paint in the color of the text, wax is warm and translucent with a pool along the baseline, and chrome is liquid mercury that ripples. The heading melts under the pointer and sets again when it leaves, follows the scroll, melts once as it comes into view and stays that way, or drips on a slow loop.

Module `text`, category Text. Import `@dioramajs/text/melt`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/text/src/melt.ts)

A summer sale banner on a dark page whose orange headline Heatwave melts into glossy paint drips under the pointer.

```html title="index.html"
<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>
```

## 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.

```html
<h1 data-dio="melt">Hot sauce</h1>
```

In page transitions: The liquid fades with the page.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'drip' \| 'wax' \| 'chrome'` | `'drip'` | drip glossy paint that runs; wax warm, slumping wax; chrome liquid mercury. |
| `trigger` (rebuilds) | `data-dio-trigger` | `'hover' \| 'scroll' \| 'view' \| 'loop'` | `'hover'` | hover melts under the pointer; scroll follows the page; view melts once; loop drips on. |
| `strength` | `data-dio-strength` | `number` 0 to 2 | `1` | How far the letters sag and the drips run; 0 keeps the shape and drips none. |
| `drips` (rebuilds) | `data-dio-drips` | `number` 0 to 40 | `12` | Number of drips across the text, spread along the undersides of the letters. At most low 8. |
| `speed` | `data-dio-speed` | `number` 0 to 3 | `1` | Pace of the melt, of setting again after a hover and of the loop. |
| `gloss` | `data-dio-gloss` | `number` 0 to 2 | `1` | Strength of the highlights and the reflections; 0 is matte. |
| `color` (rebuilds) | `data-dio-color` | `string` | `''` | Color of the liquid, any CSS color; empty uses the color of the text. |
| `seed` (rebuilds) | `data-dio-seed` | `number` 1 to 100 | `1` | Picks where the drips hang and how long each one runs. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `style`: `drip`, `wax`, `chrome`
  - `drip` glossy paint that runs.
  - `wax` warm, slumping wax.
  - `chrome` liquid mercury.
- `trigger`: `hover`, `scroll`, `view`, `loop`
  - `hover` melts under the pointer.
  - `scroll` follows the page.
  - `view` melts once.
  - `loop` drips on.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`size`](/docs/api/inputs#size), [`width`](/docs/api/inputs#input-width), [`x`](/docs/api/inputs#input-x), [`y`](/docs/api/inputs#input-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. See [how a frame is decided](/docs/concepts/frames).

## 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.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { melt: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 13.4 KB 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.

- low: At most 8 drips, and the text is rastered at 1 device pixel per CSS pixel instead of 2.

See [the quality plugin](/docs/effects/quality).

## 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.

An ice cream parlor menu on a cream page, the pink title Soft serve dripping beside a list of four flavors with prices.

```html title="index.html"
<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.

An album announcement on a dark page with the title Quicksilver in liquid chrome that drips and ripples.

```html title="index.html"
<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.

```html
<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.

## Related

- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [blinds](/docs/effects/blinds.md): A heading printed across real 3D slats that turn over in a wave, lit and casting shadows, to show it.
- [counter](/docs/effects/counter.md): Stats count up to their value on real 3D mechanics: odometer drums, slot machine reels or flip cards.
- [dust](/docs/effects/dust.md): A heading crumbles into fine sand that lifts off the page and drifts away in depth as it scrolls out, or on a click.
- [emboss](/docs/effects/emboss.md): Letters pressed into or raised out of paper, leather, brushed metal, stone or plaster, lit by a light that follows the pointer.
- [extrude](/docs/effects/extrude.md): A headline becomes a solid 3D block: beveled letters with lit side walls, seen in perspective, that turn toward the pointer.
- [fire](/docs/effects/fire.md): The letters burn: flames rise from their tops, sparks drift up in depth and the firelight flickers on the page.
- [hologram](/docs/effects/hologram.md): A heading becomes a 3D hologram: projected from a glowing emitter, built of slices in depth, crossed by scan lines.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
