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

Animation runs repeatedly in interactive mode with loop={false} #71

Open
zackdotcomputer opened this issue Sep 4, 2022 · 5 comments · May be fixed by #111
Open

Animation runs repeatedly in interactive mode with loop={false} #71

zackdotcomputer opened this issue Sep 4, 2022 · 5 comments · May be fixed by #111

Comments

@zackdotcomputer
Copy link

Describe the bug
When set to not loop and play the animation once in a block, the expectation I have is that upon entering the block the animation will play once and then not repeat. Instead, the result is that the animation plays once and then replays again on each incremental interaction.

To Reproduce
Steps to reproduce the behavior:

  1. Set up an animation with the props:
        loop={false}
        interactivity={{
          mode: "scroll",
          actions: [
            { visibility: [0, 0.3], type: "stop", frames: [0] },
            { visibility: [0.3, 1.0], type: "play", frames: [0, 38] }
          ]
        }}
  1. Scroll until 30% visible and observe one playthrough
  2. Scroll until 31% visible and observe a second playthrough

Expected behavior
The expectation would be that the playthrough would happen once while the user was in section 30%-100% and then not play again.

Desktop (please complete the following information):

  • OS: Mac
  • Browser: Chrome
  • Version: 105 (Latest)
@zackdotcomputer zackdotcomputer changed the title Animation runs repeatedly in interactive mode Animation runs repeatedly in interactive mode with loop={false} Sep 4, 2022
@zackdotcomputer
Copy link
Author

Relatedly, if one tries to circumvent this by taking a small section as your "play" section and then setting it as a "stop" section after the user leaves the section, it still doesn't work. If the user scrolls through the slice too quickly, it just jumps to the last frame:

        interactivity={{
          mode: "scroll",
          actions: [
            { visibility: [0, 0.3], type: "stop", frames: [0] },
            { visibility: [0.3, 0.31], type: "play", frames: [0, 38] },
            { visibility: [0.31, 1.0], type: "stop", frames: [38] }
          ]
        }}

@Ourselp
Copy link

Ourselp commented Sep 9, 2022

Hey @zackdotcomputer

Did you find a solution for this at the end ?
I'm facing the same problem right now

@zackdotcomputer
Copy link
Author

No, sadly.

@s7aks
Copy link

s7aks commented May 5, 2023

I'm dealing with something similar right now.

const interactivity = {
  mode: "scroll",
  actions: [
    {
      visibility: [0, 1],
      type: "play",
    }
  ],
};

const LottieTest = () => {
  return (
    <Lottie
      animationData={animationData}
      style={style}
      interactivity={interactivity}
      loop={false}
    />
  );
};

The animation plays when in viewport, but every time I scroll a lil' bit while in view it starts playing all over again.
Over at Lottie-interactivity docs, you can pass "playOnce" to "type":

https://docs.lottiefiles.com/lottie-interactivity/animation-modes#animate-when-visible-and-play-once

This doesn't work with lottie-react unfortunately.
@Gamote Can this be addressed?
https://i.postimg.cc/FzLxcS3N/Capture-d-e-cran-2022-09-09-a-15-13-52.png

@rcole1919
Copy link

rcole1919 commented Jun 20, 2023

Yes, I have same problem. You might add some loop of the animation end, and the problem will be solved

`const handler = useCallback((evt: any) => {
    if (Math.floor(evt.currentTime) === 180) {
        lottie.current && lottie.current.goToAndPlay(110, true);
    }
}, []);

return (
    <Lottie
        lottieRef={lottie}
        className={props.className}
        animationData={json}
        onEnterFrame={handler}
        interactivity={{
            mode: 'scroll',
            actions: [
                {
                    visibility: [0, 1],
                    type: 'play',
                    frames: [0],
                },
            ],
        }}
    />
);`

@chadkouse chadkouse linked a pull request Apr 23, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

4 participants