animated

ShuffleText

Animates text in by sliding each character through a scramble strip, with optional colour interpolation and scroll, hover or loop triggers.

Install

pnpm add @fractaldesign/machines-ui
import '@fractaldesign/machines-ui/style.css';
import { ShuffleText } from '@fractaldesign/machines-ui';

Preview

MACHINES UI

<ShuffleText text="MACHINES UI" tag="h2" />

Props

PropTypeDefaultDescription
text* string —The text to animate, one character per cell.
class string ''
style string ''Extra inline CSS appended to the element's style attribute.
shuffleDirection ShuffleDirection
'left''right''up''down'
'right'Direction each character slides in from: `left`, `right`, `up`, or `down`.
duration number 0.35Seconds for one character to complete its slide.
maxDelay number 0Upper bound in seconds for random stagger delays in `random` mode.
ease string | EasingFunction 'power3.out'Easing name such as `power3.out`, or a custom easing function.
threshold number 0.1Fraction of the element that must be visible before the shuffle starts.
rootMargin string '-100px'IntersectionObserver root margin, e.g. `-100px`, shrinking the trigger area.
tag TagName
'h1''h2''h3''h4''h5''h6''p''span'
'p'Element the text is rendered as: `h1`–`h6`, `p`, or `span`.
textAlign string 'center'CSS text-align value for the element.
shuffleTimes number 1How many scramble clones each character slides through.
animationMode AnimationMode
'evenodd''random'
'evenodd'Stagger pattern: `evenodd` interleaves two groups, `random` gives each character a random delay.
loop boolean falseRepeat the shuffle after each cycle.
loopDelay number 0Seconds to wait before each loop restarts.
stagger number 0.03Seconds between consecutive character delays.
scrambleCharset string ''Characters used for the scramble clones; empty means each clone shows the real character.
colorFrom string —Colour the characters interpolate from; needs `colorTo` to take effect.
colorTo string —Colour the characters interpolate to; needs `colorFrom` to take effect.
triggerOnce boolean trueStop observing after the first intersection.
respectReducedMotion boolean trueShow the plain text immediately when the user prefers reduced motion.
triggerOnHover boolean trueReplay the shuffle when the pointer enters the element.

API

  • callback onShuffleComplete () => void Called each time a shuffle cycle finishes.
  • class forwarded to the outer element
  • a11y honours prefers-reduced-motion

Types

NameKindDescription
EasingFunctiontype
(t: number) => number
ShuffleDirectiontype
'left' | 'right' | 'up' | 'down'
AnimationModetype
'evenodd' | 'random'
TagNametype
'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'span'

Theming

CSS custom properties this component reads.

  • --font-sans

src/lib/components/animated/ShuffleText.svelte

machines-ui