Lottie switch between animations

28 Views Asked by At

How to switch between lottie animations without "blank" lag? When i anim.destroy() and create new animation, my animated character disappears for a second. How to fix that?

function play_anim_win() {

    let anim = lottie.loadAnimation({
        name: "pig3",
        container: document.getElementById('piggy-visual'),
        renderer: 'svg',
        loop: false,
        autoplay: false,
        path: "/anim/pig3.json"
    });

    anim.addEventListener('complete', function() {
        anim.destroy();
        play_anim_sleep();
    })
}

function play_anim_sleep() {

    let anim = lottie.loadAnimation({
        container: document.getElementById('piggy-visual'),
        renderer: 'svg',
        loop: true,
        autoplay: true,
        path: "/anim/pig1.json"
    });
}
0

There are 0 best solutions below