Lottie-web: Define a set number of loops?

Created on 9 Jan 2019  路  5Comments  路  Source: airbnb/lottie-web

Hi,

I'm new to lottie/bodymovin and not very fluent in JS. So I would love to get a bit of help getting my animation to run twice (or loop once if you like) 鈥撀爋r preferably a way to define a set amount of loops.

Javascript:

var animation = bodymovin.loadAnimation({
    container: document.getElementById('animation-test'),
    renderer: 'svg',
    loop: false,
    autoplay: true,
    path: 'data.json'
})

This works as expected, and it runs once.

Is there a way to define a set amount of loops?

Thank you!

Most helpful comment

you can pass a number to the loop param instead of false.

All 5 comments

you can pass a number to the loop param instead of false.

Thank you for the answer!

Is it possible to show a code example?

var animation = bodymovin.loadAnimation({
    container: document.getElementById('animation-test'),
    renderer: 'svg',
    loop: 4,
    autoplay: true,
    path: 'data.json'
})

Thank you. Can't believe it was that easy, I was looking at all sorts of complicated solutions.

Much appreciated.

This only works the first time I play my animation. If I goToAndPlay(0) after that it only plays once, even if I set anim.loop = 2 before playing again.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

casillasluisn12 picture casillasluisn12  路  4Comments

Ipaulsen picture Ipaulsen  路  4Comments

Sandok-voc picture Sandok-voc  路  4Comments

dulllud picture dulllud  路  3Comments

phantomboogie picture phantomboogie  路  4Comments