Text Scramble / Matrix Decode
Text that scrambles through random characters before resolving to the final string — the classic hacker/matrix decode effect. Zero dependencies.
Code
Text Scramble / Matrix Decode
The classic hacker-movie text effect — characters scramble through a random pool before each letter resolves to its final value. Zero dependencies, pure vanilla JS with requestAnimationFrame.
How it works
A TextScramble class maintains a queue of characters to resolve. Each frame:
- For each character position, if it hasn’t resolved yet, pick a random char from the
charspool - Once a character’s frame counter reaches its threshold, lock it to the final value
- Build the full string from resolved + scrambling characters and set
el.innerHTML
chars = "!<>-_\\/[]{}—=+*^?#________";
The ________ padding biases toward blank space — slowing visible scrambling near the end for a natural feel.
Trigger modes
- Auto-plays on load
- Hover to re-trigger
- Cycles through multiple phrases with a delay