zardi Posted November 30, 2024 Posted November 30, 2024 I am a beginner in gsap and I have a next.js project with tailwindcss. What i need to do is a pinned section with 3d cards that can scroll horizontally. The user can only "pass" this section if he has scrolled all the cards in the session. Each 3d card have a rotate x animation, but this 3d animation must be start just when the scroll is in the current card. I already found a lot of "horizontal scroll" in gsap community forum but I can't apply in my case. I don't know if there is a styled in somewhere confliting the animation, or the animation settings is really bad. I have the rotate x animation already, and a simple & smooth movement in all section elements, the code is below: const triggerSection: gsap.DOMTarget | ScrollTrigger.Vars = { trigger: "#projects-section", start: "-150 40%", end: "bottom 60%", scrub: 1.6, markers: false, }; gsap.fromTo( "#projects-title", { x: "-30%", opacity: 0.6 }, { x: 0, opacity: 1, scrollTrigger: triggerSection } ); gsap.fromTo( "#projects", { x: 0, opacity: 0.6 }, { x: "-10%", opacity: 1, scrollTrigger: triggerSection } ); gsap.timeline({ scrollTrigger: { id: "project-cards-trigger", ...triggerSection } }) .fromTo(".project-card", { rotateX: 10, rotateY: 50 }, { rotateX: 0, rotateY: 0, duration: 0.8 } ) .to(".project-card", { rotateX: 10, rotateY: -50, duration: 0.8 } ); Here is my section component with tailwind: export default function ProjectsScene({}) { const { projects } = portfolio; useLayoutEffect(() => { gsap.registerPlugin(ScrollTrigger); ScrollAnimation(); return () => { UnmountAnimations(); }; }, []); return ( <section data-scroll data-scroll-section id="projects-section" className="relative flex min-h-dvh w-full flex-col items-end justify-center gap-3 px-4 sm:px-8 md:px-16 lg:px-24 xl:px-48" > <TagText id="projects-title">projects</TagText> <div id="projects" className="flex w-max items-center justify-end gap-10"> {projects.map((p) => ( <ProjectCard key={p.title} project={p as Project} /> ))} </div> </section> ); } I would like to receive any tips to work with gsap and a possible fix for my issue. If you need more details please tell me, i am available to send it. Thanks, Eric Zardo.
GSAP Helper Posted November 30, 2024 Posted November 30, 2024 Hi @zardi and welcome to the GSAP Forums! I don't have a lot of time right now to dig into everything here, but I wanted to offer you some quick advice about how to get the most out of these forums... Keep it simple. Don't list a bunch of requirements ("it should ___, and ____, and then also ____ while _____ ..." - that's too difficult to follow). Just pick the very first thing and see if you can make that work. If you get stuck, post one question focused on that one piece, like "how can I pin each section one at a time?" Keep your CodePen focused only on that one piece with as little code/markup as possible. Then once that's answered, move on to your next question/problem. Baby steps Before you know it, things will fall into place one at a time. You'll get a lot more people willing to help you if you keep things very simple and clear. A well-crafted minimal demo is GOLD around here - you'll get people falling over themselves to help you if you make a CodePen that's super clear and isolates the issue. Explain exactly how to reproduce the problem, like "scroll down to the blue section and notice how it pins before it hits the top of the viewport" for example. Don't worry - this community has got your back when it comes to GSAP-specific questions. I just wanted to provide some pointers on how to help us help you. Finally you should look into ScrollTrigger's containerAnimation feature: https://gsap.com/docs/v3/Plugins/ScrollTrigger/?page=1#containerAnimation https://gsap.com/blog/3-8/#containeranimation
GSAP Helper Posted November 30, 2024 Posted November 30, 2024 Hi there! I see you're using React - Proper cleanup is very important with frameworks, but especially with React. React 18 runs in strict mode locally by default which causes your useEffect() and useLayoutEffect() to get called TWICE. Since GSAP 3.12, we have the useGSAP() hook (the NPM package is here) that simplifies creating and cleaning up animations in React (including Next, Remix, etc). It's a drop-in replacement for useEffect()/useLayoutEffect(). All the GSAP-related objects (animations, ScrollTriggers, etc.) created while the function executes get collected and then reverted when the hook gets torn down. Here is how it works: const container = useRef(); // the root level element of your component (for scoping selector text which is optional) useGSAP(() => { // gsap code here... }, { dependencies: [endX], scope: container }); // config object offers maximum flexibility Or if you prefer, you can use the same method signature as useEffect(): useGSAP(() => { // gsap code here... }, [endX]); // simple dependency Array setup like useEffect() This pattern follows React's best practices. We strongly recommend reading the React guide we've put together at https://gsap.com/resources/React/ If you still need help, here's a React starter template that you can fork to create a minimal demo illustrating whatever issue you're running into. Post a link to your fork back here and we'd be happy to take a peek and answer any GSAP-related questions you have. Just use simple colored <div> elements in your demo; no need to recreate your whole project with client artwork, etc. The simpler the better.
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