Jump to content
Search Community

csp

Members
  • Posts

    6
  • Joined

  • Last visited

csp's Achievements

  1. Thanks Rodirigo, the percentage info helped solve my problem for why the second instance wasn't working properly. Thank you so much!
  2. Is it possible to have 2 instances of scrollTrigger? I currently have one instance on one component and then another on the component just beneath it and I'm getting some strange behavior. Side question, is it possible to use variables like vh for end values? Thanks!
  3. Yep you're right, it was the class error! It must be one of those days. Thanks Greensock! Now off to apply to my project, really appreciate the help
  4. This example from the docs is exactly what I'm trying to recreate in my code shared above. When I try to refactor this to work with Next.js and styled-components I start to get issues. Here is the codepen from the docs I am trying to recreate. Sorry I'm not too familiar with codepen and can't provide a more specific example. https://codepen.io/GreenSock/pen/yLegBwO
  5. Thanks, that seemed to get me a little further. If I make changes and save them, I can see everything working properly for a few seconds until the page refreshes. Once the page refreshes all of the animations and animation elements are gone and all i can see are the markers and the "Scroll down" text. 'use client'; import styled from 'styled-components'; import { useRef } from 'react'; import { gsap } from 'gsap/dist/gsap'; import { ScrollTrigger } from 'gsap/dist/ScrollTrigger'; import { useGSAP } from '@gsap/react'; gsap.registerPlugin(useGSAP, ScrollTrigger); const Body = styled.div` height: 300vh; `; const Trigger = styled.div` position: absolute; top: 75vh; left: 0; width: 100vw; height: 80vh; background-color: lightgray; padding: 20px; `; const Box = styled.div` background-color: black; width: 10vw; height: 10vw; `; export default function Home() { const container = useRef(); useGSAP( () => { const tl = gsap.timeline({ scrollTrigger: { trigger: '.trigger', start: 'top top', end: '+=1000', scrub: 1, pin: true, markers: true, }, }); tl.to('.box', { yPercent: 350, duration: 1 }); tl.to('.box', { rotation: 360, duration: 3 }); tl.to('.box', { xPercent: 350, duration: 1 }); }, { scope: container } ); return ( <Body ref={container}> <h1>Scroll down</h1> <Trigger class="trigger"> <Box class="box"></Box> </Trigger> </Body> ); }
  6. GSAP is exactly the animation library I've been looking for, but for the life of my I can't figure out how to incorporate it into my project. Just to practice and play around I created a completely new Next project that is using styled-components and no css. I'm not sure if I'm setting something up wrong or what, but every time I try and sort of animation, as soon as the viewport hits the "start" marker everything disappears. Here is my current code which is very simple ( I am copying exactly from the scrub: true demo in the GSAP docs). Am I possibly importing incorrectly? 'use client'; import styled from 'styled-components'; import { gsap } from 'gsap/dist/gsap'; import { ScrollTrigger } from 'gsap/dist/ScrollTrigger'; import { useGSAP } from '@gsap/react'; gsap.registerPlugin(ScrollTrigger); const Body = styled.div` height: 300vh; `; const Trigger = styled.div` position: absolute; top: 75vh; left: 0; width: 100vw; height: 80vh; background-color: lightgray; padding: 20px; `; const Box = styled.div` background-color: black; width: 10vw; height: 10vw; `; export default function Home() { useGSAP(() => { const tl = gsap.timeline({ scrollTrigger: { trigger: '.trigger', start: 'top top', end: '+=1000', scrub: 1, pin: true, markers: true, }, }); tl.to('.box', { yPercent: 350, duration: 1 }); tl.to('.box', { rotation: 360, duration: 3 }); tl.to('.box', { xPercent: 350, duration: 1 }); }, []); return ( <Body> <h1>Scroll down</h1> <Trigger class="trigger"> <Box class="box"></Box> </Trigger> </Body> ); }
×
×
  • Create New...