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

Define a set number of loops? #1450

Closed
NoLooseEnds opened this issue Jan 9, 2019 · 7 comments
Closed

Define a set number of loops? #1450

NoLooseEnds opened this issue Jan 9, 2019 · 7 comments

Comments

@NoLooseEnds
Copy link

NoLooseEnds commented Jan 9, 2019

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) – or 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!

@NoLooseEnds NoLooseEnds changed the title Set the number of loops? Define a set number of loops? Jan 9, 2019
@bodymovin
Copy link
Collaborator

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

@NoLooseEnds
Copy link
Author

Thank you for the answer!

Is it possible to show a code example?

@bodymovin
Copy link
Collaborator

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

@NoLooseEnds
Copy link
Author

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

Much appreciated.

@JanSzidat
Copy link

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.

BrainCrumbz referenced this issue in Quanyails/lottie-web Apr 21, 2022
I found out how `playSegments()` and `loop` interact through this issue,
which I found would be helpful to include in the documentation:
airbnb#689 (comment)
@cheestudio
Copy link

@bodymovin 4 years later and this advice still works. Amazing how the docs list the "loop" property as a simple boolean in the React docs, yet passing an integer worked perfectly!

https://docs.lottiefiles.com/lottie-player/components/lottie-react/properties

@reatlat
Copy link

reatlat commented Aug 21, 2024

new link here https://developers.lottiefiles.com/docs/dotlottie-player/dotlottie-web/properties/

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

5 participants