Skip to main content

Lottie

Render Lottie animations with automatic or programmatic playback control.

anim, _ := lottie.Load(f)

widgets.Lottie{
Source: anim,
Width: 200,
Height: 200,
Repeat: widgets.LottieLoop,
}

Lottie Properties

PropertyTypeDescription
Source*lottie.AnimationPre-loaded Lottie animation. If nil, renders nothing.
Widthfloat64Display width. If zero and Height is set, derived from aspect ratio.
Heightfloat64Display height. If zero and Width is set, derived from aspect ratio.
RepeatLottieRepeatRepeat mode. Ignored when Controller is set.
Controller*animation.AnimationControllerExternal controller for programmatic playback. Disables auto-play.
OnCompletefunc()Called when play-once finishes. Ignored with Controller or looping modes.

LottieRepeat Values

ValueDescription
LottiePlayOncePlay once and stop at the last frame (default)
LottieLoopReplay from the beginning continuously
LottieBouncePlay forward then backward continuously (ping-pong)

Loading Functions

FunctionDescription
lottie.Load(r io.Reader)Parse from any reader (asset file, HTTP body)
lottie.LoadBytes(data []byte)Parse from raw bytes
lottie.LoadFile(path string)Parse from a file path