Overview
This code snippet combines a classic typewriter effect with a blinking cursor, followed by a smooth highlight that animates behind a specific word. It demonstrates advanced layering techniques to create polished, production-ready text animations.Complete Code
What This Snippet Demonstrates
Dual-Layer Technique
Dual-Layer Technique
Uses two text layers—one for typing with cursor, one for the final highlighted state—to achieve smooth transitions without flickering.
Smooth Cursor Blink
Smooth Cursor Blink
The cursor fades in/out using
interpolate() with a sine-like pattern for natural blinking, not abrupt on/off.Spring-Animated Highlight
Spring-Animated Highlight
The yellow highlight expands from left to right using
scaleX with spring physics for organic, bouncy motion.Responsive Sizing
Responsive Sizing
Font size scales with video width (
width * 0.075) to ensure text looks good at any resolution.Key Concepts
Character-by-Character Reveal:finalLayerOpacity = 1) while the typewriter layer remains visible underneath.
Highlight Positioning: The highlight uses absolute positioning with transformOrigin: "left center" and scaleX to expand from left edge.
Spring Timing: Delays highlight by 10 frames after typing ends, then animates over 22 frames with bounce.
When to Use This Pattern
- Call-to-action text with emphasis on key words
- Tutorial or instructional content highlighting important terms
- Brand messaging with hero words
- Quote animations emphasizing the punchline
- Educational content drawing attention to key concepts
Customization Tips
- Text & Target
- Colors
- Cursor
- Animation
Change
FULL_TEXT and HIGHLIGHT_WORD (must be substring). Adjust CHAR_FRAMES for faster/slower typing.