Text Scramble
TheTextScramble component creates a captivating scramble animation effect where random characters rapidly cycle before resolving to the target text. Perfect for attention-grabbing headings, tech-themed interfaces, and dynamic content reveals.
Installation
Import
Usage
Props
string
required
The final text to display after the scramble animation completes.
number
default:"50"
Animation speed in milliseconds between character updates. Lower values = faster scrambling.
number
default:"3"
Total duration of the scramble animation in seconds.
boolean
default:"true"
Whether to trigger the animation. Set to
false to show final text without animation.string
Additional CSS classes. Component uses
font-mono by default.string
Custom set of characters to use during scrambling.
React.ElementType
default:"'span'"
HTML element type to render (span, div, h1, etc.).
() => void
Callback function fired when scramble animation completes.
Animation Details
Algorithm
The component uses a progressive reveal algorithm:- Starts with all characters scrambled
- Progressively reveals characters from left to right
- Characters to the left of
currentIndexare finalized - Characters to the right continue scrambling
- Spaces are preserved throughout
Timing
The animation interval runs at the specifiedspeed, incrementing the reveal index:
The animation automatically cleans up intervals on unmount to prevent memory leaks.
Examples
Hero Heading
Matrix-Style Effect
Sequential Reveals
Interactive Button
Loading State
Character Set Examples
Performance Considerations
- Uses
setIntervalfor character updates - Automatically cleans up on unmount
- Minimal re-renders (only when scrambled text changes)
- Lightweight algorithm with O(n) complexity
Use Cases
- Tech/cyberpunk themed websites
- Loading states with personality
- Hero section headings
- Terminal/CLI interfaces
- Gaming UIs
- Data visualization reveals
- Countdown timers
- Easter eggs and hidden messages
Accessibility
- Final text is always readable
- Screen readers will announce the final text
- Animation can be disabled with
trigger={false} - Consider reduced motion preferences for sensitive users