my.createLottieContext

Call this API with Lottie id passed in to create and return a Lottie context object lottieContext. Lottie id is the ID property that the developer freely names to identify the corresponding Lottie tag. You can manipulate a Lottie component through lottieContext. For more information, see Lottie.

Usage

Sample code

.axml

Write the following code in the .axml file and assign a value to the Lottie id, for example, myLottie:

copy
<!--.axml-->
<lottie
          assets-path="{{item.assetsPath}}" 
          autoplay="{{item.autoplay}}" 
          id="myLottie"
          django-id="{{item.djangoId}}"
          path="{{item.path}}" 
          repeat-count="{{item.repeatCount}}"
          placeholder="{{item.placeholder}}"
          class="item">
  </lottie>

.js

Write the following code in the .js file:

copy
//.js
var lottieContext = my.createLottieContext('myLottie');
lottieContext.play();

lottieContext methods

Method

Parameter

Data type

Description

play

N/A

-

Starts to play.

stop

N/A

-

Stops playing.

pause

N/A

-

Pause.

setSpeed({value:$value})

$value: Number

Float

Sets the speed of the animation. A positive number indicates the animation's fast forward speed while a negative number indicates the animation's rewound speed.

Note: The default value is 1.0, which means the animation is played at normal speed.

Example: setSpeed({value:1.5})

goToAndStop({value:$value})

$value: Number

Value range [0.0~1.0]

Float

Moves the animation to the target progress specified by value and stops it there.

Example: goToAndStop({value: 0.5]})

goToAndPlay({value:$value})

$value: Number

Value range [0.0~1.0]

Float

Moves the animation to the target progress specified by value and plays from that progress.

Example: goToAndPlay({value: 0.5]})

playFromMinToMaxProgress({min:$min,max:$max})

$min: Number

$max: Number

Value range [0.0~1.0]

Float

Plays the animation from the minimum to the maximum progress interval.

Example: playFromMinToMaxProgress({min:0.2,max:0.8})

playFromMinToMaxFrame({min:$min,max:$max})

$min: Number

$max: Number

Integer

Plays the animation from the minimum to the maximum frame interval.

downgradeToPlaceholder

N/A

-

Downgrades the current Lottie animation to the default image specified by the placeholder parameter.