跳到主要内容

lottie

Lottie component, used to integrate and display Lottie animations in mini programs. Lottie animation is an animation library developed by Airbnb, which uses JSON format animation data and can run on various platforms such as web pages and mobile applications.

Example

Page({
data: {
instance: null,
renderer: 'svg',
loop: true,
autoplay: true,
path: 'pages/packageAPI/pages/read-file/lottie.json',
rendererSettings: {
preserveAspectRatio: "xMidYMid slice"
},
},
onReady() {
this.instance = bn.createLottieContext('lottie')
},
play() {
this.instance.play()
},
pause() {
this.instance.pause()
},
stop() {
this.instance.stop()
},
setSpeed() {
this.instance.setSpeed(0.25)
},
setDirection() {
this.instance.setDirection(-1)
},
destroy() {
this.instance.destroy()
},
play2() {
this.instance2.play()
},
stop2() {
this.instance2.stop()
},
})
  <theme-context>
<view class='container'>
<head title='lottie'></head>
<view class='page-body'>
<lottie
lottie-id="lottie"
renderer="{{renderer}}"
loop="{{loop}}"
path="{{path}}"
autoplay="{{autoplay}}"
renderer-settings="{{rendererSettings}}
class="lottie">
</lottie>
<button class="play" bindtap="play">
play
</button>
<button class="stop" bindtap="stop">
stop
</button>
<button class="pause" bindtap="pause">
pause
</button>
<button class="setSpeed" bindtap="setSpeed">
setSpeed
</button>
<button class="setDirection" bindtap="setDirection">
setDirection - reverse
</button>
<button class="destroy" bindtap="destroy">
destroy
</button>
</view>
</view>
</theme-context>
 .lottie {
width: 300px;
height: 200px;
}

Props

NameTypeDescriptionDefault
lottieIdstringUnique lottie id for keeping context
renderersvg|canvas|htmlto set the renderer modesvg
loopbooleanActivate loop animationtrue
autoplaybooleantrue / false it will start playing as soon as it is readytrue
pathstringthe local path to the animation object
rendererSettingRendererSettingsTo set the mode of the renderer
initialSegment[number, number]initial Animation Segment

Events

lottieContextEvents

NameDescription
playplay animation
stopstop animation
pausepause animation
destroydestroy animation
setSpeedset animation speed, speed: 1 is normal speed
setDirectiondirection: 1 is forward, -1 is reverse.