momo12 Posted August 15, 2023 Posted August 15, 2023 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!
GSAP Helper Posted August 15, 2023 Posted August 15, 2023 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: React (please read this article!) Next Svelte Sveltekit Vue Nuxt 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.
momo12 Posted August 15, 2023 Author Posted August 15, 2023 Here is the Codepen: See the Pen GRwVbdb by talewoy290 (@talewoy290) on CodePen.
mvaneijgen Posted August 15, 2023 Posted August 15, 2023 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. 2
momo12 Posted August 15, 2023 Author Posted August 15, 2023 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.
Rodrigo Posted August 15, 2023 Posted August 15, 2023 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: See the Pen bGxOjeP by GreenSock (@GreenSock) on CodePen. Hopefully this helps. Happy Tweening! 1
momo12 Posted August 15, 2023 Author Posted August 15, 2023 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.
mvaneijgen Posted August 16, 2023 Posted August 16, 2023 @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. 1
momo12 Posted August 16, 2023 Author Posted August 16, 2023 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.
Solution mvaneijgen Posted August 16, 2023 Solution Posted August 16, 2023 Yeah, that is what @Rodrigo explained in his example. See the Pen oNJvZmX?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen. 2
momo12 Posted August 16, 2023 Author Posted August 16, 2023 2 minutes ago, mvaneijgen said: Yeah, that is what @Rodrigo explained in his example. See the Pen See the Pen oNJvZmX?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen. by mvaneijgen (@mvaneijgen) on CodePen Thanks a lot
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now