Jump to content
Search Community

GSAP Helper last won the day on January 1

GSAP Helper had the most liked content!

GSAP Helper

Moderators
  • Posts

    0
  • Joined

  • Last visited

  • Days Won

    1

Community Answers

  1. GSAP Helper's post in GSAP Scroll Trigger parallax was marked as the answer   
    We love helping with GSAP-related questions, but unfortunately we just don't have the resources to provide free general consulting, logic troubleshooting, or "how do I recreate this cool effect I saw on another site?" tutorials. Of course anyone else is welcome to post an answer if they'd like - we just want to manage expectations.  
     
    If you're looking for ScrollTrigger effects, I'd recommend looking at the demos at https://greensock.com/st-demos and https://codepen.io/collection/DkvGzg and https://codepen.io/collection/AEbkkJ - you may be able to use one of those as a jumping-off point. 
     
    You are welcome to post in the "Jobs & Freelance" forum for paid consulting, or contact us directly. 
     
    Otherwise, if you've got a GSAP-specific question just post that here along with a minimal demo and we'd be happy to take a look. 
  2. GSAP Helper's post in Scoping Issue with GSAP Timeline in React Componen was marked as the answer   
    Hi there! I see you're using React -

    Proper animation 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.
    In GSAP 3.11, we introduced a new gsap.context() feature that helps make animation cleanup a breeze. All you need to do is wrap your code in a context call. All GSAP animations and ScrollTriggers created within the function get collected up in that context so that you can easily revert() ALL of them at once.
    Here's the structure:
    // typically it's best to useLayoutEffect() instead of useEffect() to have React render the initial state properly from the very start. useLayoutEffect(() => { let ctx = gsap.context(() => { // all your GSAP animation code here }); return () => ctx.revert(); // <- cleanup! }, []); This pattern follows React's best practices, and one of the React team members chimed in here if you'd like more background.
    We strongly recommend reading the React information we've put together at https://greensock.com/react
    Happy tweening!
  3. GSAP Helper's post in Please Help fix pinning issue was marked as the answer   
    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 (avoid frameworks if possible). 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
     
    If you're using something like React/Next/Vue/Nuxt or some other framework, you may find StackBlitz easier to use. We have a series of collections with different templates for you to get started on these different frameworks: React/Next/Vue/Nuxt.
     
    Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 
  4. GSAP Helper's post in Scrolling through items with a header that will be fixed in the background was marked as the answer   
    Howdy! 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 animate over each section, and gradient colors over those children, force animation on hero load and then have ScrollTrigger take over dynamically...and I think my code is a mess so please help clean it up" - that's too hard 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.
     
    Again, try not to list out all the problems. Break them apart. You'll get a lot more people willing to help you if you keep things 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. 
  5. GSAP Helper's post in Animation with ScrollTrigger and ScrollToPlugin has some jerky was marked as the answer   
    Have you tried this?: 
    ScrollTrigger.normalizeScroll(true); And/or this?: 
    ScrollTrigger.config({ ignoreMobileResize: true });  
  6. GSAP Helper's post in making a scale animation, but facing some css translate property issues was marked as the answer   
    Hi there! I see you're using React -

    Proper animation 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.
    In GSAP 3.11, we introduced a new gsap.context() feature that helps make animation cleanup a breeze. All you need to do is wrap your code in a context call. All GSAP animations and ScrollTriggers created within the function get collected up in that context so that you can easily revert() ALL of them at once.
    Here's the structure:
    // typically it's best to useLayoutEffect() instead of useEffect() to have React render the initial state properly from the very start. useLayoutEffect(() => { let ctx = gsap.context(() => { // all your GSAP animation code here }); return () => ctx.revert(); // <- cleanup! }, []); This pattern follows React's best practices, and one of the React team members chimed in here if you'd like more background.
    We strongly recommend reading the React information we've put together at https://greensock.com/react
    Happy tweening!
  7. GSAP Helper's post in Nest Multiple Master Timelines in One Sequence was marked as the answer   
    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 CodeSandbox that demonstrates the issue? 
     
    Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). 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
     
    Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 
  8. GSAP Helper's post in Need help combining full page scroll and pinned ScrollTrigger sections was marked as the answer   
    I read your question a few times and I'm still pretty lost. What do you mean by "add a full page scroll"? The whole page is scrolling in that demo. 
     
    And what do you mean by "so the scrolling would be easy"? It seems very easy to me. "...wouldn't have to scroll twice" - are you saying you want the user to be able to do just one small move of their mouse wheel or one tiny touch gesture and have it move all the way to the next section? If so, you probably need to look at Observer plugin. There's a demo on that page that does exactly that. 
  9. GSAP Helper's post in Next.js 13 and GSAP: Issues with Animations Using Experimental appDir was marked as the answer   
    Perhaps the problem is that React 18 runs in "strict" mode locally by default which causes your useEffect() to get called TWICE! Very annoying. It has caused a lot of headaches for a lot of people outside the GSAP community too.
     
    .from() tweens use the CURRENT value as the destination and it renders immediately the value you set in the tween, so when it's called the first time it'd work great but if you call it twice, it ends up animating from the from value (no animation). It's not a GSAP bug - it's a logic thing.
     
    For example, let's say el.x is 0 and you do this: 
    useEffect(() => { // what happens if this gets called twice?   gsap.from(el, {x: 100}) }, []);  
    The first time makes el.x jump immediately to 100 and start animating backwards toward the current value which is 0 (so 100 --> 0). But the second time, it would jump to 100 (same) and animate back to the current value which is now 100 (100 --> 100)!  See the issue?
     
    In GSAP 3.11, we introduced a new gsap.context() feature that solves all of this for you. All you need to do is wrap your code in a context call, and then return a cleanup function that reverts things: 
    // typically it's best to useLayoutEffect() instead of useEffect() to have React render the initial state properly from the very start. useLayoutEffect(() => { let ctx = gsap.context(() => { // all your GSAP animation code here }); return () => ctx.revert(); // <- cleanup! }, []);  
    We strongly recommend reading the React article at https://greensock.com/react
     
    Happy tweening!
  10. GSAP Helper's post in Timing error was marked as the answer   
    By the way, these color names are NOT in the list of supported ones: lightgreen, limegreen. If GSAP supported every possible named color, it would bloat the file size too much. So just convert those to hex colors or rgb() or almost anything else. 
     
  11. GSAP Helper's post in React+GSAP scrollTrigger pin is faulty on v. 3.11.4 but works on 3.9.1 was marked as the answer   
    Hm, it's tough to troubleshoot blind but it sure sounds like you're being bitten by the React 18 double-invoke of useEffect()/useLayoutEffect(), leading to creating of duplicate/competing animations/ScrollTriggers. Don't worry, there's a very easy solution. 
     
    First, I'd strongly recommend reading this article:
     
    In GSAP 3.11, we introduced a new gsap.context() feature that solves all of this for you. All you need to do is wrap your code in a context call, and then return a cleanup function that reverts things: 
    // typically it's best to useLayoutEffect() instead of useEffect() to have React render the initial state properly from the very start. useLayoutEffect(() => { let ctx = gsap.context(() => { // all your GSAP animation code here }); return () => ctx.revert(); // <- cleanup! }, []); If you're still having trouble, would you mind providing a minimal demo that clearly shows the issue? Here's a Stackblitz starter that you can just fork: https://stackblitz.com/edit/react-cxv92j?file=src%2FApp.js
     
    I did it myself with that CodePen you provided and it seems to work fine - am I missing something?:
    https://stackblitz.com/edit/react-r1subh?file=src%2FApp.js,src%2Fstyle.css,src%2Findex.js
  12. GSAP Helper's post in RWD bug? was marked as the answer   
    Welcome to the forums, @Sean Coding.
     
    It's definitely not ideal to try to troubleshoot via a Github link like that - you'll have a much better chance of getting a solid answer here if you provide a CodePen or CodeSandbox or Stackblitz. Here's a React starter template that you can fork. 
     
    One thing I noticed was that it looks like you're not doing proper cleanup which is pretty important in React. React 18 actually double-invokes useEffect()/useLayoutEffect() which means you might inadvertently be creating duplicate/competing animations/observers. I'd definitely recommend reading this article:
     
    gsap.context() is your new best friend in React because it makes cleanup so simple (plus the scoped selectors can be super convenient). 
     
    useLayoutEffect(() => { let ctx = gsap.context(() => { // put all your GSAP-related code here }); return () => ctx.revert(); // <-- cleanup! }, []);  
    I'd recommend wrapping your stuff properly in a gsap.context() and do proper cleanup, and then if you're still having trouble, post a Stackblitz that clearly shows the issue and we'd be happy to take a peek. 
  13. GSAP Helper's post in React with GSAP causing multiple trigger on scroll and showing multiple marker was marked as the answer   
    Perhaps the problem is that React 18 runs in "strict" mode locally by default which causes your useEffect() to get called TWICE! Very annoying. It has caused a lot of headaches for a lot of people outside the GSAP community too.
     
    .from() tweens use the CURRENT value as the destination and it renders immediately the value you set in the tween, so when it's called the first time it'd work great but if you call it twice, it ends up animating from the from value (no animation). It's not a GSAP bug - it's a logic thing.
     
    For example, let's say el.x is 0 and you do this: 
    useEffect(() => { // what happens if this gets called twice?   gsap.from(el, {x: 100}) }, []);  
    The first time makes el.x jump immediately to 100 and start animating backwards toward the current value which is 0 (so 100 --> 0). But the second time, it would jump to 100 (same) and animate back to the current value which is now 100 (100 --> 100)!  See the issue?
     
    In GSAP 3.11, we introduced a new gsap.context() feature that solves all of this for you. All you need to do is wrap your code in a context call, and then return a cleanup function that reverts things: 
    // typically it's best to useLayoutEffect() instead of useEffect() to have React render the initial state properly from the very start. useLayoutEffect(() => { let ctx = gsap.context(() => { // all your GSAP animation code here }); return () => ctx.revert(); // <- cleanup! }, []);  
    One of the React team members chimed in here if you'd like more background.
     
    We strongly recommend reading the React article at https://greensock.com/react
     
    Happy tweening!
  14. GSAP Helper's post in how to keep the moving element where it is at the end of the animation with scrollTrigger was marked as the answer   
    If you can't replicate it without React - Perhaps the problem is that React 18 runs in "strict" mode locally by default which causes your useEffect() to get called TWICE! Very annoying. It has caused a lot of headaches for a lot of people outside the GSAP community too.
     
    .from() tweens use the CURRENT value as the destination and it renders immediately the value you set in the tween, so when it's called the first time it'd work great but if you call it twice, it ends up animating from the from value (no animation). It's not a GSAP bug - it's a logic thing.
     
    For example, let's say el.x is 0 and you do this: 
    useEffect(() => { // what happens if this gets called twice?   gsap.from(el, {x: 100}) }, []);  
    The first time makes el.x jump immediately to 100 and start animating backwards toward the current value which is 0 (so 100 --> 0). But the second time, it would jump to 100 (same) and animate back to the current value which is now 100 (100 --> 100)!  See the issue?
     
    In GSAP 3.11, we introduced a new gsap.context() feature that solves all of this for you. All you need to do is wrap your code in a context call, and then return a cleanup function that reverts things: 
    // typically it's best to useLayoutEffect() instead of useEffect() to have React render the initial state properly from the very start. useLayoutEffect(() => { let ctx = gsap.context(() => { // all your GSAP animation code here }); return () => ctx.revert(); // <- cleanup! }, []);  
    One of the React team members chimed in here if you'd like more background.
     
    We strongly recommend reading the React article at https://greensock.com/react
     
    Happy tweening!
  15. GSAP Helper's post in Elements return to their start position when they should stay was marked as the answer   
    Perhaps the problem is that React 18 runs in "strict" mode locally by default which causes your useEffect() to get called TWICE! Very annoying. It has caused a lot of headaches for a lot of people outside the GSAP community too.
     
    .from() tweens use the CURRENT value as the destination and it renders immediately the value you set in the tween, so when it's called the first time it'd work great but if you call it twice, it ends up animating from the from value (no animation). It's not a GSAP bug - it's a logic thing.
     
    For example, let's say el.x is 0 and you do this: 
    useEffect(() => { // what happens if this gets called twice?   gsap.from(el, {x: 100}) }, []);  
    The first time makes el.x jump immediately to 100 and start animating backwards toward the current value which is 0 (so 100 --> 0). But the second time, it would jump to 100 (same) and animate back to the current value which is now 100 (100 --> 100)!  See the issue?
     
    In GSAP 3.11, we introduced a new gsap.context() feature that solves all of this for you. All you need to do is wrap your code in a context call, and then return a cleanup function that reverts things: 
    // typically it's best to useLayoutEffect() instead of useEffect() to have React render the initial state properly from the very start. useLayoutEffect(() => { let ctx = gsap.context(() => { // all your GSAP animation code here }); return () => ctx.revert(); // <- cleanup! }, []);  
    One of the React team members chimed in here if you'd like more background.
     
    We strongly recommend reading the React article at https://greensock.com/react
     
    Happy tweening!
  16. GSAP Helper's post in Fullwidth draggable slider and mobile scroll issue. was marked as the answer   
    You'll significantly improve your chances of getting a solid answer if you provide a minimal demo like in CodePen. 
     
    Are you saying that you've got a big full-screen Draggable element that can be dragged in any direction (vertical and horizontal) and you ALSO want to be able to touch-scroll on mobile devices? If so, that seems logically impossible to discern whether the person intends to drag the element or scroll the page. 
     
    If you set the type of Draggable to "x" or "left", you could leverage the allowNativeTouchScrolling: true option to ensure that vertical swipes of the finger are interpreted as scroll ones. But it looks like in your demo you didn't set a type, so it's using the default of "x,y". 
     
    If you still need some help, 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
     
    Or if you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 
  17. GSAP Helper's post in Sticky header to top on scroll with GSAP was marked as the answer   
    We love helping with GSAP-related questions, but unfortunately we just don't have the resources to provide free general consulting, logic troubleshooting, or "how do I recreate this cool effect I saw on another site?" tutorials. Of course anyone else is welcome to post an answer if they'd like - we just want to manage expectations.  
     
    If you're looking for ScrollTrigger effects, I'd recommend looking at the demos at https://greensock.com/st-demos and https://codepen.io/collection/DkvGzg and https://codepen.io/collection/AEbkkJ - you may be able to use one of those as a jumping-off point. 
     
    You are welcome to post in the "Jobs & Freelance" forum for paid consulting, or contact us directly. 
     
    Otherwise, if you've got a GSAP-specific question just post that here along with a minimal demo and we'd be happy to take a look. 
  18. GSAP Helper's post in How to stop the horizontal scroll section bottom content to not scroll by? was marked as the answer   
    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 CodeSandbox that demonstrates the issue? 
     
    Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). 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
     
    If you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 
     
    Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 
  19. GSAP Helper's post in I am trying to create an onScroll animation for my Menu burger was marked as the answer   
    We love helping with GSAP-related questions, but unfortunately we just don't have the resources to provide free general consulting, logic troubleshooting, or "how do I recreate this cool effect I saw on another site?" tutorials. Of course anyone else is welcome to post an answer if they'd like - we just want to manage expectations.  
     
    If you're looking for ScrollTrigger effects, I'd recommend looking at the demos at https://greensock.com/st-demos and https://codepen.io/collection/DkvGzg and https://codepen.io/collection/AEbkkJ - you may be able to use one of those as a jumping-off point. 
     
    You are welcome to post in the "Jobs & Freelance" forum for paid consulting, or contact us directly. 
     
    Otherwise, if you've got a GSAP-specific question just post that here along with a minimal demo and we'd be happy to take a look. 
  20. GSAP Helper's post in Jerky animation when scrolling up and down continuously was marked as the answer   
    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 CodeSandbox that demonstrates the issue? 
     
    Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). 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
     
    If you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 
     
    Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 
  21. GSAP Helper's post in Some elements won't update using tailwindcss. was marked as the answer   
    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 CodeSandbox that demonstrates the issue? 
     
    Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). 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
     
    If you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 
     
    You might want to try setting scroll-behavior: auto because I think tailwind applies smooth which can interfere with measurements/behavior. 
     
    Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 
  22. GSAP Helper's post in trying not to go outside panel was marked as the answer   
    One problem for sure is that you're making one of the common mistakes - nesting multiple ScrollTriggers inside tweens in a timeline. That's logically impossible to have the timeline's playhead control the tween AND the scrollbar's position ALSO control the playhead (they could be going in very different places). 
     
    You've got a lot of questions here - why don't you just tackle one at a time? Create one new question in the forums with a VERY simplified demo that only focused on that one thing. For example, if you want things to stay in the viewport when being resized, create a CodePen that just has a couple of colored <div> elements that show what you're trying to do. It's fine if it's broken - you can say "how can I create the red and purple <div> elements inside the viewport at all times?" for example. 
     
    Once you get that figured out, we can move to your next challenge. Create a minimal demo that's only focused on that one thing, and post it as a new thread. Fair enough? 
     
    By the way, if you're looking for ScrollTrigger effects, I'd recommend looking at the demos at https://greensock.com/st-demos and https://codepen.io/collection/DkvGzg and https://codepen.io/collection/AEbkkJ - you may be able to use one of those as a jumping-off point. 
     
    Don't worry - you can do this. We're here to help with any of your GSAP/ScrollTrigger-specific questions (we just can't provide free consulting for all the other logic, CSS, etc.)  👍
  23. GSAP Helper's post in "Expected an assignment or function call and instead saw an expression" was marked as the answer   
    It's pretty tough to troubleshoot without a minimal demo but I'm confident this has absolutely nothing to do with GSAP. It's something else in your code somewhere. Maybe it has to do with the fact that you put commas between your gsap.from() calls rather than semicolons. If you're still having trouble, please include a minimal demo like a CodePen that clearly shows the problem.
     
    Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). 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
     
    If you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 
     
    Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 
  24. GSAP Helper's post in GSAP shape morph (bouncing square to triangle) was marked as the answer   
    We love helping with GSAP-related questions, but unfortunately we just don't have the resources to provide free general consulting, logic troubleshooting, or "how do I recreate this cool effect I saw on another site?" tutorials. Of course anyone else is welcome to post an answer if they'd like - we just want to manage expectations.  
     
    You can post in the "Jobs & Freelance" forum for paid consulting, or contact us directly. 
     
    Your animation may benefit from MorphSVGPlugin. It looks like it's largely about tweaking the timings and eases. 
     
    Otherwise, if you've got a GSAP-specific question just post that here along with a minimal demo and we'd be happy to take a look. 
  25. GSAP Helper's post in Problem with Text disappearing (React, Tailwind, Gsap, ScrollTrigger) was marked as the answer   
    It's tough to say for sure without a minimal demo, but I bet the problem is that React 18 runs in "strict" mode locally by default which causes your useEffect() to get called TWICE! Very annoying. It has caused a lot of headaches for a lot of people outside the GSAP community too.
     
    .from() tweens use the CURRENT value as the destination and it renders immediately the value you set in the tween, so when it's called the first time it'd work great but if you call it twice, it ends up animating from the from value (no animation). It's not a GSAP bug - it's a logic thing.
     
    For example, let's say el.x is 0 and you do this: 
    useEffect(() => { // what happens if this gets called twice?   gsap.from(el, {x: 100}) }, []);  
    The first time makes el.x jump immediately to 100 and start animating backwards toward the current value which is 0 (so 100 --> 0). But the second time, it would jump to 100 (same) and animate back to the current value which is now 100 (100 --> 100)!  See the issue?
     
    So you can either turn off strict mode in React or you can add some conditional logic to your useEffect() call so that it only runs ONCE. Sorta like:
    const didAnimate = useRef(false); useEffect(() => { // if we already ran this once, skip! if (didAnimate.current) { return; } // otherwise, record that we're running it now and continue... didAnimate.current = true;   gsap.from(el, {x: 100}); }, []);  
    Or you could just use .fromTo() tweens so that you define both the start and end values.
     
    One of the React team members chimed in here if you'd like more background.
×
×
  • Create New...