Jump to content
Search Community

Hiding a component before the animation starts

DavTho test
Moderator Tag

Recommended Posts

I need to stop the flicker that happens on loading a React component with an SVG inside, so that the SVG appears offscreen at the start. I'm using React Hooks and a simple setTimeOut inside a useEffect hook to control a display property does not seem to work. 

 

This animation code works, but produces a flicker:

 

  const mortarBoard = useRef(null);
 
  useEffect(() => {
  
    const tl = new TimelineMax();
    tl.fromTo("#mortarboard"5, { y: 1200 }, { y: 0 });
    
  }, []);

 

whereas this code the flicker is not noticeable:

 

  const mortarBoard = useRef(null);
 
  useEffect(() => {
    TweenMax.fromTo(
      [mortarBoard.current],
      0.5,
      { x: 5y: 18 },
      { x: -5y: -40yoyo: truerepeat: 3 }
    );
 
    
  }, []);

 

 

How do I hide the component before the animation starts?

 

 

Link to comment
Share on other sites

Hey DavTho and welcome to the GreenSock forums!

 

We actually have a Quick Tip that was made just for this sort of thing. It's not React-based, but the core issue and solution is the same:

 

Essentially, you set the styles in your CSS to hide the element and then un-hide it once the page has loaded via JS.

 

Let us know if you have any other questions!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...