Jump to content
Search Community

Gsap animation is working different on nextjs

ArshErgon test
Moderator Tag

Recommended Posts

Hey, I am creating this cards effect in gsap for nextjs , this is the same code I am using for my nextjs project but the problem is its going downwards in a reverse manner, but in the pen its working fine,

this is my code:
 

const cardRefs = useRef([]);

gsap.registerPlugin(ScrollTrigger);
gsap.registerPlugin(useGSAP);
	useGSAP(() => {
		
const cards = gsap.utils.toArray(".Card");
let lastCardST = ScrollTrigger.create({
    trigger: cards[cards.length-1],
    start: "center center"
});
let stickDistance = 0;

cards.forEach((card, index) => {
    var scale = 1 - (cards.length - index) * 0.025;
    let scaleDown = gsap.to(card, {scale: scale, 'transform-origin': '"100% '+ (lastCardST.start + stickDistance) +'"' });
  
    const tween = gsap.to(card, {
        scrollTrigger: {
            trigger: card,
            scrub: true,
            markers: true,
            invalidateOnRefresh: true,
            start: "center center",
            end: () => lastCardST.start + stickDistance, 
            pin: true,
            markers: true,
            pinSpacing: false,
            ease: "easeInOut",
            animation: scaleDown,
            toggleActions: "restart none none reverse"
        },
        ease: "easeInOut",
        scale: () => 1 - (cards.length - index) * 0.025
    });

    ScrollTrigger.create({
        trigger: card,
        start: "top top",
        pin: true,
        pinSpacing: false,
        markers: true,
        id: 'pin',
        end: 'max',
        invalidateOnRefresh: true,
        end: "bottom center"
    });
});

	}, []);

html:
return (
		<section>
			<div id="cards-wrapper" className="Cards flex overflow-hidden flex-col flex-nowrap flex-none justify-start content-center items-center w-full pt-[100px] pb-[30px] border-[1px] border-[solid] border-[green] relative">
			<div id="card" className="Card bg-teal-500 relative mb-[10px] rounded-xl w-[90vh] h-[300px] top-0 overflow-visible origin-[50%_-160%]">Something</div>
			<div id="card" className="Card bg-yellow-500 relative mb-[10px] rounded-xl w-[90vh] h-[300px] top-0 overflow-visible origin-[50%_-160%]">Hello</div>
			<div id="card" className="Card bg-blue-500 relative mb-[10px] rounded-xl w-[90vh] h-[300px] top-0 overflow-visible origin-[50%_-160%]">Something</div>
			<div id="card" className="Card bg-[#7fff00] relative mb-[10px] rounded-xl w-[90vh] h-[300px] top-0 overflow-visible origin-[50%_-160%]">Something</div>
			<div id="card" className="Card bg-[#bbfb3c] relative mb-[10px] rounded-xl w-[90vh] h-[300px] top-0 overflow-visible origin-[50%_-160%]">Something</div>
			</div>		
		</section>
	)

I try to change the reverse in the toggleActions but still its not working. I have seen different questions try to replicate them its working well in the codepen but on nextjs its again start to behave different.

I want it to be like this: https://stickycards.framer.website/
issue video: https://imgur.com/a/F8zeZd9

See the Pen rNbXaZw by Arsh-Ergon (@Arsh-Ergon) on CodePen

Link to comment
Share on other sites

Hi @ArshErgon and welcome to the GSAP Forums!

 

Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates 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 dependencies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

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

that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

 

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

8 hours ago, ArshErgon said:

I'm trying to replicating this design: https://stickycards.framer.website/ my codepen() with the same code replicating the design but when I try to paste the code in nextjs its breaking down either its reversing the card animation or when in view its push the card on the bottom.

Hi,

 

I'm not sure what could be the issue here without a minimal demo, clearly something in the styles you're applying is causing this, because the tailwind styles in Jack's demo are working as expected.

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