Lottie-web: Trigger event on anim data load

Created on 10 Mar 2017  路  14Comments  路  Source: airbnb/lottie-web

I want to trigger an event once bodymovin.loadAnimation() is complete.
I'm testing this with anim.isLoaded and it's returning false unless I put a setTimeout on it.

Is it possible to fire an event once my anim data is loaded?

Thank you!

Most helpful comment

you can use events 'data_ready', 'config_ready' or 'DOMLoaded' depending at which point you need to hook to them

All 14 comments

you can use events 'data_ready', 'config_ready' or 'DOMLoaded' depending at which point you need to hook to them

Fantastic, this works perfectly with 'DOMLoaded'. Thank you Hernan!

@processprocess and @bodymovin, can you share an example of this? I am not sure how to specifically use DOMLoaded. Is the event listener added to the bodymovin object or the animation instance?

@awingit it's added to the animation instance.

thanks @bodymovin , would it be used like this:

var _anim = bodymovin.loadAnimation(_options); _anim.addEventListener('DOMLoaded ', function(e) { console.log('element loaded'); });

yes, exactly.

Is there anything in the options that would prevent that event from firing? The animation loads but that event does not trigger...

you have an trailing space: 'DOMLoaded ', if you remove it, it should work.

Typical :P . Thanks bodymovin! Really enjoying the project I am working on using this plugin!

Hello, i have similar problem with events, idk but i cant find solution. here is my code.

`var preLoad = bodymovin.loadAnimation({
container: document.getElementById('pre-animate'),
renderer: 'svg',
loop: 1,
autoplay: true,
path: 'assets/json/pre-anime.json'
});
preLoad.addEventListener('loopComplete', function (e) {

                console.log('done');
                //$('#pre-animate').fadeOut();
                //preLoad.destroy();

            });`

I also try something like:

preLoad = bodymovin.loadAnimation({ container: document.getElementById('pre-animate'), renderer: 'svg', loop: 1, autoplay: true, path: 'assets/json/pre-anime.json', onComplete: function(){ // code here} });

also didn't work for me.

If you're setting loop to 1, it's better if you use the "complete" event instead of the "loopComplete".
If it doesn't work, can you share a link where I can check your implementation?

Thanks, probably every solution worked but i have problem with json file because animation is completed but i must wait about 1min and after this my events start.

@bodymovin The initial time is too long, Is there a solution to avoid it? I use react.

@OnlyBreak hi, can you explain some more?

Was this page helpful?
0 / 5 - 0 ratings