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.00f4d05f.js"></script>   <!-- only on pages that use it -->

Attributes

AttributeValuesDefault
data-reanimator-wordsthe other phrases, separated by |required
data-reanimator-effecttype · backspace · slide · rise · blur · flip · scrambleslide
data-reanimator-holdmilliseconds each phrase stays2400
data-reanimator-pacespeed multiplier for the transitions1
data-reanimator-loopsstop after this many passes through all the phrases, resting on the first; forever never stops3

Tokens

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

TokenDefaultWhat it does
--reanimator-duration560msOne phrase leaving and the next arriving (the word effects and scramble)
--reanimator-easecubic-bezier(.2,.8,.2,1)The easing of those transitions
--reanimator-selectvar(--color-brand)The selection sweep in type
--reanimator-select-textvar(--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.