Methods

The following methods are accessible using the player instance.

enterInteractiveMode: (stateId) => void

Activate the passed state machine.

getContainer: () => HTMLDivElement | undefined

Returns the div element containing the Lottie animation.

getCurrentAnimationId: () => string | undefined

Returns the currently playing animation Id.

getLottie: () => AnimationItem | undefined

Return the AnimationItem instance.

getManifest: () => Manifest | undefined

Returns the .lottie Manifest.

next: (getOptions) => void

Plays the next animation.

Usage:

// Go to next animation
lottieRef.current?.next();
// Or go to next animation and use speed=3 and direction=-1
lottieRef.current?.next((curr, manifest) => {
    return {
        ...curr,
        speed: 3,
        direction: -1,
    }
});

play: (indexOrId, getOptions) => void

Starts playing. Or you can pass indexOrId to switch and play another animation.

Usage:

// Plays currently stopped or paused animation
lottieRef.current?.play();
// Or plays animationId `wifi` and applies speed=3 and direction=-1
lottieRef.current?.play('wifi', (curr, manifest) => {
    return {
        ...curr,
        speed: 3,
        direction: -1,
    }
});x

previous: (getOptions) => void

Plays the previous animation from the .lottie manifest.

// Go to previous animation
lottieRef.current?.previous();
// Or go to previous animation and use speed=3 and direction=-1
lottieRef.current?.previous((curr, manifest) => {
    return {
        ...curr,
        speed: 3,
        direction: -1,
    }
});

playOnScroll: (scrollOptions) => void

Sync the animation to the scrolling of the page.

stopPlayOnScroll() => void

Stop playing on scroll.

playOnShow(playOnShowOptions) => void

Play the animation when it appears on screen.

stopPlayOnShow() => void

Stop play on show.

reset: () => void

Goes back to initial animation. activeAnimationId or index 0 .

resize: () => void

Resize the animation.

getCurrentAnimationId: () => string | undefined

Returns the currently active animation Id.

getState: () => DotLottiePlayerState

Returns the current player states.

getVersions() => { lottieWebVersion: string, dotLottiePlayerVersion: string }

Returns the version of lottie-web and the dotlottie player.

Returns

Type: Versions

setAutoplay: (autoplay: boolean) => void

Sets autoplay

setBackground: (background: string) => void

Sets background

setDefaultTheme: (defaultTheme: string) => void

Applies theme

setDirection: (direction: AnimationDirection) => void

Sets play direction direction

setHover: (hover: boolean) => void

Sets play on hover

setIntermission: (intermission: number) => void

Sets the pause between loops

setLoop: (loop: number | boolean) => void

Sets loop

setPlayMode: (mode: PlayMode) => void

Sets play mode.

setSpeed: (speed: number) => void

Sets speed

seek: (frame: number) => void

Seek to a frame.

revertToManifestValues: (playbackKeys) => void

It ignores the props sets by the player and uses manifest.

Usage:

// To to use `speed` and `direction` from manifest
lottieRef.current?.revertToManifestValues(['speed', 'direction']);
// or to reset all PlaybackOptions
lottieRef.current?.revertToManifestValues([]);

Last updated