Methods
Explains how to call the methods that the Lottie-React component supports.
Get Player instance
To call methods on the instance of the Player component, get a reference to the component and call the methods on ref.current
. This is essentially Reacts equivalent of document.getElementById().
You may then use this reference to call methods that are described in the React documentation.
The following example demonstrates obtaining the instance of the Player and playing an animation.
Get Lottie instance
The lottieRef
property returns the Lottie animation instance that you can use to set data and call methods as described in the bodymovin documentation.
The following example demonstrates retrieving a Lottie instance and playing an animation using the instance.
Lottie-React Methods
The Lottie-React component supports the following methods:
Method: pause()
Purpose: Pauses animation play.
Return Type: void
-----------------------------------------------
Method: play()
Purpose: Plays the animation.
Return Type: void
-----------------------------------------------
Method: setPlayerDirection(direction: 1 | -1 )
Purpose: Sets the direction of play.
Parameters:
Name | Type | Description |
---|---|---|
|
| Direction values. Either |
Return Type: void
----------------------------------------------------------
Method: setPlayerSpeed(speed?: number)
Purpose: Sets the animation playback speed.
Parameters:
Name | Type | Description |
---|---|---|
|
| Playback speed. The value must be any positive integer.
The default value is |
Returns
Type: void
----------------------------------------------------------
Method: stop()
Purpose: Stops animation playback.
Return Type: void
----------------------------------------------------------
Method: getVersions()
Purpose: Returns the version of lottie-web used, as well as the current player's version.
Return Type: { lottieWebVersion: string, lottiePlayerVersion: string }
----------------------------------------------------------
Method: setSeeker(frame: number | string, play: boolean)
Purpose: Seek to a given frame.
Parameter: The frame value can either be a number or a percent string (for example, 50%).
Return Type: void
To get the total number of frames in the animation, use:
Passing an invalid value to seek()
causes the animation to be played from the start.
Last updated