Jump to content
Search Community

GSAP Flip issue

momo12 test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

sap.registerPlugin(ScrollTrigger, Flip);

const main = document.querySelector(".small-grid");
const blue = document.querySelector(".title-sticky-wr");
const boxes = gsap.utils.toArray(".grid-item-wr");

function flipBoxes(target, container) {
    let state = Flip.getState(boxes);
    boxes.forEach((box) => container.appendChild(box));
    return Flip.from(state, {
        scale: true,
        ease: "power3.out",
        duration: 1,
        stagger: 0.2
    });
}

ScrollTrigger.create({
    trigger: "#one",
    start: "top top",
    end: "bottom bottom", // ScrollTrigger end parameter changed
    onToggle: self => {
        if (self.isActive) {
            flipBoxes(blue, main);
        }
    }
});

ScrollTrigger.create({
    trigger: "#one",
    start: "bottom top", // ScrollTrigger start parameter changed
    end: "top bottom", // ScrollTrigger end parameter changed
    onToggle: self => {
        if (self.isActive) {
            flipBoxes(main, blue);
        }
    }
});

Hello guys, I havethis code which reparents the grid-item-wr on scroll with Flip library from main to blue on scroll and when we scroll up again, it reparents the grid-item-wr once again from blue to main. But not working!

Link to comment
Share on other sites

It's pretty tough 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 Stackblitz that demonstrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. 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

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

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

Link to comment
Share on other sites

The best thing to do is to have the flip already happen on page load and then just .play(), .reverse(), ect at the point you want.

 

I've forked your pen removed the function and given the tween a name, then I can just call .play() and .reverse() on it, based on onEnter of the ScrollTrigger or onLeave.

 

I'm not sure what it is you want to do, so please change it for the logic you want, but I don't see why you need multiple ScrollTriggers for it. Also be sure to set markers: true, so that you can see what is going on. Because in your original pen start: "top top", end: "bottom bottom",  will result in it being completed when it starts, so nothing will happen.

 

Hope it helps and happy tweening! 

 

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

  • Like 2
Link to comment
Share on other sites

5 hours ago, mvaneijgen said:

The best thing to do is to have the flip already happen on page load and then just .play(), .reverse(), ect at the point you want.

 

I've forked your pen removed the function and given the tween a name, then I can just call .play() and .reverse() on it, based on onEnter of the ScrollTrigger or onLeave.

 

I'm not sure what it is you want to do, so please change it for the logic you want, but I don't see why you need multiple ScrollTriggers for it. Also be sure to set markers: true, so that you can see what is going on. Because in your original pen start: "top top", end: "bottom bottom",  will result in it being completed when it starts, so nothing will happen.

 

Hope it helps and happy tweening! 

 

 

 

Is there a way to make it responsive to scroll position? As we scroll down, they get reparented.

Link to comment
Share on other sites

11 minutes ago, Rodrigo said:

Hi,

 

As shown in this example you can't scrub the reparenting of the elements, that is going to happen when creating the Flip instance. What you can do is scrub the timeline that the Flip.from() method returns:

 

 

 

Hopefully this helps.

Happy Tweening!

I couldn't understand this code. I could manage to create something else and was hopeful someone might be help me to learn to do what I'm after.

Link to comment
Share on other sites

@momo12 I'm not sure what you question is. 

 

10 hours ago, momo12 said:

Is there a way to make it responsive to scroll position? As we scroll down, they get reparented.

 

Making things responsive has more to to with CSS then with GSAP. We have gsap.matchMedia() https://greensock.com/docs/v3/GSAP/gsap.matchMedia() if you want to have other things happen on different screen sizes. But I don't get what should be responsive in this case. 

  • Like 1
Link to comment
Share on other sites

4 minutes ago, mvaneijgen said:

@momo12 I'm not sure what you question is. 

 

 

Making things responsive has more to to with CSS then with GSAP. We have gsap.matchMedia() https://greensock.com/docs/v3/GSAP/gsap.matchMedia() if you want to have other things happen on different screen sizes. But I don't get what should be responsive in this case. 

I don't want the reparenting happens as an animation. Like what scroll trigger does, I want the grid cells moves and gets reparented slowly as we scroll down. 

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...