# Re: Animator

https://docs.kleaver.ie/sfx/reanimator/

SFX

# Re: Animator

A phrase inside a line of text that swaps for others, in seven styles. The words around it never move: the swapped phrase always takes the room of the longest one. It's for the "Do X in Y" headline, where Y keeps changing.

Websites that are *quick to build.*

The subtitle is never animated. It sits below and stays put, because the headline reserves its tallest case.

The panel at the bottom right changes the effect, timing and phrases of this headline. **Copy markup** gives you the element.

## Effects

The same markup with a different data-reanimator-effect.

### Highlight and type type

Websites that are *quick to build.*

Selects the old words, replaces them, then types the new ones.

### Backspace and type backspace

Websites that are *quick to build.*

Deletes letter by letter, then types.

### Slide up slide

Websites that are *quick to build.*

The old words slide up and out while the new ones rise into the same slot.

### Letter rise rise

Websites that are *quick to build.*

The same, one letter at a time with a short stagger.

### Blur fade blur

Websites that are *quick to build.*

Cross-fades through a soft blur. The quietest of the set.

### Flip flip

Websites that are *quick to build.*

Rotates like a departures board.

### Scramble scramble

Websites that are *quick to build.*

Random letters settle into the new words.

## Markup

Put class="reanimator" and data-reanimator on a <span> inside the line. Its own text is the first phrase. Keep the full stop inside the phrases so it travels with them.

```
<h1>Websites that are
  <em><span class="reanimator" data-reanimator data-reanimator-loops="forever" data-reanimator-effect="slide"
        data-reanimator-words="easy to change.|yours to keep.">quick to build.</span></em>
</h1>

<script defer src="scripts/reanimator.js"></script>   <!-- only on pages that use it -->
```

## Attributes

| Attribute | Values | Default |
| --- | --- | --- |
| data-reanimator-words | the other phrases, separated by \| | required |
| data-reanimator-effect | type · backspace · slide · rise · blur · flip · scramble | slide |
| data-reanimator-hold | milliseconds each phrase stays | 2400 |
| data-reanimator-pace | speed multiplier for the transitions | 1 |
| data-reanimator-loops | stop after this many passes through all the phrases, resting on the first; forever never stops | 3 |

## Tokens

The look is a token, set in the client's theme.css.

| Token | Default | What it does |
| --- | --- | --- |
| --reanimator-duration | 560ms | One phrase leaving and the next arriving (the word effects and scramble) |
| --reanimator-ease | cubic-bezier(.2,.8,.2,1) | The easing of those transitions |
| --reanimator-select | var(--color-brand) | The selection sweep in type |
| --reanimator-select-text | var(--color-bg) | Text colour on the selection. Keep the contrast. |

## Writing the phrases

- **The box is as big as the longest phrase.** That is what keeps the surrounding text still, at any width.
- **Keep the phrases close in length.** If the longest wraps onto a second line, every phrase gets two lines of room, and the short ones leave a blank line. The room on the first line depends on the font and the screen, so there is no fixed character limit. The script logs a warning in the browser console when the phrases wrap to different numbers of lines.
- **Only the phrase animates.** Subtitles and other copy stay static, and are pushed down by the reserved height.
- **Make each phrase work on its own.** Screen readers and anyone without JavaScript only get the first one.

## Behaviour and limits

- **Opt-in.** A site whose pages have no .reanimator gets none of its CSS or JavaScript. The script is not part of the shared bundle.
- **Reduced motion, no JavaScript.** The first phrase, still. No animation and no timers.
- **Accessibility.** The animated copy is hidden from screen readers, which read the first phrase once. It pauses while the pointer is over it, off screen and in a hidden tab. Text that changes by itself for longer than five seconds should be pausable (WCAG 2.2.2), so it also stops by itself after three passes through the phrases (data-reanimator-loops) and rests on the first one. The examples on this page use forever so you can keep watching them; real pages shouldn't.
- **Any theme.** It only moves text, so it works in light and dark.
- **One phrase per line of text** is the intended use. Several on a page are fine and each runs on its own.

## Catalog

Re: Animator (in `components.css`)  ·  SFX #2  ·  see **`reanimator.html`**

| Component | Markup | Use for |
|---|---|---|
| Re: Animator | `<span class="reanimator" data-reanimator data-reanimator-words="b\|c">a</span>` inside a line of text (usually a headline) | The "Do X in Y" headline where Y keeps changing. Seven effects: `type`, `backspace`, `slide`, `rise`, `blur`, `flip`, `scramble`. |

- **Attributes** (on the span): `data-reanimator-words` (the other phrases, `|`-separated; the span's own text is the first), `data-reanimator-effect` (default `slide`), `data-reanimator-hold` (ms, 2400), `data-reanimator-pace` (1), `data-reanimator-loops` (stop after n passes through the phrases, resting on the first; default **3**; `forever` for demos).
- **Tokens** (in `theme.css`): `--reanimator-duration`, `--reanimator-ease`, `--reanimator-select`, `--reanimator-select-text` (see `THEMING.md`).
- **Script:** `<script defer src="scripts/reanimator.js"></script>` on the page. The span becomes a one-cell grid holding an invisible copy of every phrase, so it is always as big as the longest and **the text around it never moves**. Keep the full stop inside the phrases.
- **Rules:** only the phrase animates, never a subtitle (the reserved height pushes it down). Keep phrases close in length: if the longest wraps to a second line, every phrase gets two lines, and the console warns when phrases wrap to different numbers of lines.
- **Accessibility:** no JS or reduced motion = the first phrase, still; screen readers get the first phrase only (the animated copy is `aria-hidden`); pauses off screen, in a hidden tab and under the pointer. It stops by itself after 3 passes (`data-reanimator-loops`) so the page doesn't move for ever (WCAG 2.2.2).
- **Event:** `reanimator:set` on the span with `detail { effect, hold, pace, words, loops }` (the docs panel uses it).
- **Tuning:** `reanimator.html` has a live panel; **Copy markup** gives the element.
