AnimationUpdated in v15

Split Text

Reveals text piece by piece when it scrolls into view.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrSplitText } from 'ngwr/bits/split-text';

@Component({ imports: [WrSplitText] })
export class MyComponent {}
Angular adaptation of an effect by David Haz / reactbits.dev.

Playground

Hello, ngwr!
<!-- rootMargin is "-100px" by default, which holds the animation until the
     text is 100px INSIDE the viewport. The playground overrides it so the
     replay fires where the demo already sits. -->
<wr-split-text
  text="Hello, ngwr!"
  splitType="chars"
  [delay]="40"
  [duration]="1.2"
  rootMargin="0px"
/>

Customize

Split Type
Stagger Delay (ms)
40
Duration (s)
1.2 s
Text

Server rendering

Prerendered text stays as it is when the page hydrates. The entrance plays when the component is created in the browser and when text changes. Since v15.

API

NameDescriptionTypeDefault
textrequiredText to animate.string—
splitTypeSplit granularity.'chars' | 'words''chars'
delayStagger delay between pieces in ms.number50
durationAnimation duration in seconds.number1.25
easingCSS easing function.string'cubic-bezier(0.16, 1, 0.3, 1)' (~power3.out)
fromStart state for each piece. Properties: opacity, x, y (px), scale, rotate (deg).WrSplitTextMotion{ opacity: 0, y: 40 }
toEnd state for each piece. Same shape as from.WrSplitTextMotion{ opacity: 1, y: 0 }
thresholdIntersectionObserver threshold (0..1).number0.1
rootMarginIntersectionObserver rootMargin.string'-100px'
textAlignText alignment on the host.'left' | 'center' | 'right' | 'justify''center'
(animationComplete)Emitted once all pieces finish animating.void—

See also