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

How to let lottie file have full width height of screen when resize #87

Open
lazarus2019 opened this issue Mar 29, 2023 · 2 comments
Open

Comments

@lazarus2019
Copy link

No description provided.

@joshua-isaac
Copy link

joshua-isaac commented Jul 11, 2023

@lazarus2019 I created a helper function to help with this, changing the preserveAspectRatio attribute helped with the lottie size on resize:

import { LottieContainer } from "./constants";

export const svgHelper = () => {
  const lottie = document.getElementsByClassName(
    LottieContainer
  )[0] as HTMLDivElement;

  const svg = lottie.getElementsByTagName("svg")[0];

  if (svg) {
    svg.setAttribute("preserveAspectRatio", "xMidYMid slice");
  }
};

Then I just call it inside a useEffect:

  useEffect(() => {
    svgHelper();
  }, []);

Works for me

@joshua-isaac
Copy link

@lazarus2019 looking at it now, looks like you can use the renderSettings prop on the <Lottie /> component:

 <Lottie
    lottieRef={lottieRef}
    animationData={scrollLottieReveal}
    autoplay={false}
    rendererSettings={{
       preserveAspectRatio: "xMidYMid slice",
    }}
 />

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

2 participants