Methods

Describes the JavaScript methods to load and play animation in the Lottie-Svelte player.

Use the following JavaScript methods to load and play animations using the Lottie-Svelte player.

Lottie-Svelte Player Methods

Method: freeze()

Purpose: Freezes the animation at the current frame.

Parameter: None

Return Type: void

-----------------------------------------------

Method: getLottie()

Purpose: Returns the lottie-web instance used in this lottie-svelte component .

Return Type: Object

-----------------------------------------------

Method: getVersions()

Purpose: Returns the version of lottie-web used, as well as the current player's version.

Return Type: { lottieWebVersion: string, svelteLottiePlayerVersion: string }

-----------------------------------------------

Method: load(src: string | object)

Purpose: Load (and play) a given Bodymovin animation.

Parameters:

Return Type: void

--------------------------------------------------------

Method: pause()

Purpose: Pauses the animation.

Return Type: void

----------------------------------------------------------

Method: play()

Purpose: Plays the animation.

Return Type: void

----------------------------------------------------------

Method: setBackground(color: string)

Purpose: Sets the background color.

Parameters:

Return Type: void

----------------------------------------------------------

Method: setDirection(value: number)

Purpose: Sets the direction of play.

Parameters:

Return Type: void

----------------------------------------------------------

Method: setLooping(value: boolean)

Purpose: Enables or disables looping the animation.

Parameters:

Returns

Type: void

----------------------------------------------------------

Method: setSpeed(value?: number)

Purpose: Sets the animation playback speed.

Parameters:

Returns

Type: void

----------------------------------------------------------

Method: stop()

Purpose: Stops animation playback.

Return Type: void

----------------------------------------------------------

Method: seek(value: number | string)

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:

animation.getLottie().totalFrames

Passing an invalid value to seek() causes the animation to be played from the start.

----------------------------------------------------------

Method: snapshot(download?: boolean)

Purpose: Snapshot the current frame as SVG.

Parameter: Either true or false. If the download argument is true, a download of the snapshot is triggered in the browser.

The default value is true.

Return Type: string

--------------------------------------------------------

Method: toggleLooping()

Purpose: Toggles animation looping. If the looping is set to true, toggleLooping() sets it to false, and vice versa.

Parameter: None

Return Type: void

--------------------------------------------------------

Method: togglePlay()

Purpose: Toggles playing state.

Parameter: None

Return Type: void

--------------------------------------------------------

Method: toggleZoom()

Purpose: Toggles zooming the animation.

Parameter: None

Return Type: void

--------------------------------------------------------

Method: resize()

Purpose: Resizes the animation to the dimensions of the device on which it is being played.

Parameter: None

Return Type: void

Last updated