Jump to content
Search Community

Flip and ScrollTrigger scrub is "jumping" when going backwards

Giacomo Franco test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

Hi! how is it going?

Context

Recently I've been working on a proyect on which I have to implement FLIP, Timeline and ScrollTrigger... Basically the animation goes this way, a little bit of context:

At first I have a laptop SVG covering the entire screen, when the user scrolls, the SVG goes from the full screen to a child container on it, while the user is scrolling the animation is running ( for this I'm using the scrub property in ScrollTrigger), when the SVG is positioned where it has to be at the end, a SVG phone appears  and goes next to the laptop. (In the Codepen that i've just created doesn't appear the phone, it isn't important at the moment)

What's happening?

I have 2 problems;

When the page loads for the first time the laptop is positioned where it has to be covering the full screen, the first problem occurs when I scroll just after the end of the scroll, the SVG "Jumps"  and when I scroll back the SVG is not positioned to the top of the page as it was before (please open the codepen in fullscreen so you can see the bug better).

The other problem is that I can't make it responsive, when I set the parent to 
flex-wrap: wrap-reverse; it breaks and the laptop doesn't fit in the container and overflows the viewport 
 

See the Pen NWomZvx by GiacomoFranco (@GiacomoFranco) on CodePen

Link to comment
Share on other sites

  • Solution

Hi @Giacomo Franco welcome to the forum!

 

I've set absolute to false and the jump goes away an to me it looks perfect. Is there something I'm missing? 

 

See the Pen xxMNBPY?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen

 

8 hours ago, Giacomo Franco said:

The other problem is that I can't make it responsive, when I set the parent to flex-wrap: wrap-reverse; it breaks and the laptop doesn't fit in the container and overflows the viewport 

 

 

Do you a pen with these settings, so that we can help you debug.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 4 weeks later...

Hi @Rodrigo thanks for your suggest, I've tried to apply this resize in my project but I'm also using timeline with flip, and whenever I resize the screen I think I restart the flip but also the timeline and I don't know how to proceed (I'm implementing GSAP in an Angular project)

Screenshot_3.png

Link to comment
Share on other sites

Ahhh yeah I see the problem now. Super simple, you're not putting the laptop element back to it's original parent node on the resize event. This is what happens:

  1. You have the laptop in the original parent
  2. You run the anim method, which gets the state and reparents the laptop
  3. You resize the screen, at this point everything is reverted by GSAP Context BUT (there's always one of those, isn't it? 😁) the laptop element is inside it's final parent, not the original one, so when Flip get the state is doing what's supposed to, but the initial and final states are the same. See the problem?

This seems to fix it:

let flipCtx;
function anim() {
  flipCtx && flipCtx.revert();
  originalContainer.appendChild(laptop);
  laptop.style.cssText = "";

  flipCtx = gsap.context(() => {
    const state = Flip.getState(laptop);
    newContainer.appendChild(laptop);

    const flip = Flip.from(state, {
      scale: true
    });
  });
}

anim();

window.addEventListener("resize", anim);

Here is a fork of your demo:

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

 

Hopefully this helps.

Happy Tweening!

  • Like 1
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...