Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to listen to the 'complete' event #251

Open
christina-wilfing opened this issue Jul 16, 2024 · 0 comments
Open

Not able to listen to the 'complete' event #251

christina-wilfing opened this issue Jul 16, 2024 · 0 comments

Comments

@christina-wilfing
Copy link

christina-wilfing commented Jul 16, 2024

I would like to play several LottiePlayers in the same container one after the other.
It is possible to listen if the player is ready and set the first element to play().
However, listening to whether the animation is finished to start the next one doesn't work. (neither 'complete' nor 'loop')

Where is my error?

(My project is older and therefore still uses jquery ...)

let player;
let lottieArea = $('.js-lottie-area');
let lottiePlayers = lottieArea.find('.js-lottie-delay');
let current = 0; 

function playNextLottie() {
    if (current >= lottiePlayers.length) {
        return;
    }

    player = lottiePlayers[current];
    $(player).on('ready', function () {
        create({
            // mode: 'scroll',
            player: player,
            container: lottieArea
        })
        player.play();
    });

    $(player).on('complete', function () {
         current++;
         playNextLottie();
    });

    $(player).on('loop', function () {
         current++;
         playNextLottie();
    });

}

playNextLottie();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant