Jump to content
GreenSock

Matthew Meaklim

GSAP from, to and fromto

Go to solution Solved by GreenSock,

Recommended Posts

Hello,

 

Just starting playing about with GSAP last weekend and so far so good... more or less.

 

I've created a pretty basic loading animation (following an old YouTube tutorial), but I'm having a bit of bother with the .to, .from, .fromTo methods and am unsure which I should actually be using. The problem with what I've done as it stands is that on load the loader itself flickers. I know why it does it, I just don't know how to fix it.

 

You can see the problem here, https://ilimitado.studio/.

 

HTML

 

<div id="loader_wrapper" class="fixed loader_wrapper">
    <div id="loader" class="fixed loader">
        
    </div>
</div>

 

SCSS

 

.loader_wrapper {
    width: 100%;
    height: 100vh;
    background-color: $companyColourOne;
    z-index: 98;

 

    .loader {
        width: 12%;
        min-width: 120px;
        height: 36vh; <--- Issue (probs)
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background-color: $companyColourSeven;
        z-index: 98;
    }
}

 

JS

 

var loaderTimeline = gsap.timeline();

 

loaderTimeline.from('#loader', 1.2, {
    height: '0vh',
    y: '33vh',
    transformOrigin: '50% 100%',
    ease: Expo.easeInOut
});

 

loaderTimeline.to('#loader', 1.2, {
    height: '0vh',
    y: '-33vh',
    transformOrigin: '50% -100%',
    ease: Expo.easeInOut
});

 

So yeah, I did try playing about with the heights in the CSS, and the from and to methods, but the above is as good as I could get it.

 

Apologies in advance if this question is poorly formulated... new here.😆

 

Thanks,

 

Matthew

Link to comment
Share on other sites

Hi there, welcome!

 

It's pretty tough for us to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

  • Like 1
Link to comment
Share on other sites

Speaking as someone who is also relatively new to GSAP, I really recommend the courses @Carl runs at creativecodingclub.com. Having already gone through many, many hours of the content on there I can tell you there's some really good, clear information on the difference between from, to, and fromTo tweens as well as the "flicker" you mentioned and how to address it. 

 

 

  • Like 5
Link to comment
Share on other sites

  • Solution

Welcome! 

 

It's tough to diagnose without a minimal demo (like a CodePen), but I assume this is what you need: 

 

And yes, Carl's resources are fantastic. 👍

  • Like 3
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.
×