tomg55555 Posted November 8, 2023 Share Posted November 8, 2023 Hi there, It's my first post here I hope I can find some help here since I tried to look everywhere but did not find any solution to my issue. I'm trying to replicate the effect seen on this website "https://hervebaillargeon.com/", in the section above the landing where when you scroll down some videos are pinned and vertically overlapped. I'm working in a nextjs framework so react based solutions would be awesome but vanilla js it's super fine I'll figure out how to adjust it. As reference I used this codepen: but what I cannot really understand is how can I implement that in a container which is not scrollable by itself but is content is scrolled and pinned while scrolling the page. Thank you for the help! See the Pen KKpLdWW by GreenSock (@GreenSock) on CodePen Link to comment Share on other sites More sharing options...
Solution Toso Posted November 8, 2023 Solution Share Posted November 8, 2023 i think that's what you looking for, my demo is an old one so you may find some weird stuff See the Pen bGOZvYP?editors=0010 by GreenSock (@GreenSock) on CodePen See the Pen gOqmjeO?editors=0110 by ahmed-attia (@ahmed-attia) on CodePen 1 1 Link to comment Share on other sites More sharing options...
tomg55555 Posted November 9, 2023 Author Share Posted November 9, 2023 Thank you so much for your help Rodrigo, as expected I'm having troubles translating this from JS to NextJs. I'll show you errors I'm getting: 1st: end: () => "+=" + cards.length * cards[0].offsetHeight cards[0].offsetHeight, cards is giving me an error. 2nd: cards.slice(1).forEach((card, i) => { tl.fromTo(card, { yPercent: 0 again card in the middle line is underlined in red. I suppose the problem is at the beginning when I do create the array but I can't really understand what I'm doing wrong here. import React, {useEffect, useRef} from 'react'; import {gsap} from 'gsap' import {ScrollTrigger} from 'gsap/dist/ScrollTrigger' const Scroller = () => { gsap.registerPlugin(ScrollTrigger); const component = useRef(null); useEffect(() => { let ctx = gsap.context(() => { // create as many GSAP animations and/or ScrollTriggers here as you want... let cards = gsap.utils.toArray(".card"); console.log(cards.length); console.log(cards[0]); let tl = gsap.timeline({ scrollTrigger: { trigger: ".card-wrapper", pin: ".page-wrapper", start: "top top", scrub: true, markers: true, end: () => "+=" + cards.length * cards[0].offsetHeight } }); tl.add(() => { console.log("card", 1, "in place") }, 0.001); cards.slice(1).forEach((card, i) => { tl.fromTo(card, { yPercent: 0 }, { yPercent: -100, duration: 0.5 }); tl.add(() => { console.log("card", (i+2), "in place"); }) }) gsap.from("h1", { // <- selector text, scoped to this component! opacity: 0, y: 100, ease: "power3", duration: 2 }); }, component); }, []); return ( <div ref={component}> <div className="page-wrapper"> <div className="wrapper"> <div className="card-wrapper"> <div className="card card-1"> 1 </div> <div className="card card-2"> 2 </div> <div className="card card-3"> 3 </div> <div className="card card-4"> 4 </div> <div className="card card-5"> 5 </div> <div className="card card-6"> 6 </div> </div> </div> </div> </div> ); }; export default Scroller; Link to comment Share on other sites More sharing options...
GSAP Helper Posted November 9, 2023 Share Posted November 9, 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. Link to comment Share on other sites More sharing options...
tomg55555 Posted November 9, 2023 Author Share Posted November 9, 2023 here it is the stack blitz, I don't know why is working there but not locally on my app. https://stackblitz.com/edit/nextjs-fzthv4?file=pages%2Findex.js Registrazione schermo 2023-11-09 alle 12.34.08.mov Link to comment Share on other sites More sharing options...
tomg55555 Posted November 9, 2023 Author Share Posted November 9, 2023 1 hour ago, tomg55555 said: here it is the stack blitz, I don't know why is working there but not locally on my app. https://stackblitz.com/edit/nextjs-fzthv4?file=pages%2Findex.js Registrazione schermo 2023-11-09 alle 12.34.08.mov I was missing the return function of the use effect. return () => ctx.revert(); 1 Link to comment Share on other sites More sharing options...
Rodrigo Posted November 10, 2023 Share Posted November 10, 2023 On 11/9/2023 at 10:07 AM, tomg55555 said: I was missing the return function of the use effect. return () => ctx.revert(); Yep.... that happens to the best of us. Great that you found the problem! Happy Tweening! 1 Link to comment Share on other sites More sharing options...
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