Akash Ranjan Posted May 30, 2023 Posted May 30, 2023 Hi, I am trying to do animation on one element with gsap.fromTo and then later control that animation in a timeline with scrollTrigger. But the issue is that whenever I refresh the page and the page refreshes and show the content from middle on the webpage then the gsap.fromTo animation runs which it should not. Below is my code for better understanding. As you can see If the page reloads from middle then the .h1-text should not be visible if we scroll up but it is showing because of that gsap.fromTo animation. Please help me in fixing the issue gsap.fromTo( '.h1-text', { autoAlpha: 0, yPercent: 100, }, { autoAlpha: 1, yPercent: 0, duration: 1, ease: 'power2.out', } ) let LaserHeroTl = gsap.timeline({ ease: 'power2.out', scrollTrigger: { trigger: laserHeroContainer.current, // markers: true, start: '10% 25%', end: '75% 10%', scrub: 0.6, }, }) LaserHeroTl.fromTo( '.satelite-1', { transform: 'rotate3d(1, 1, 1, 15deg)', }, { transform: 'rotate3d(1, 1, 1, -10deg)', duration: 1, ease: 'power2.out', } ) .to( '.h1-text', { yPercent: 100, opacity: 0, duration: 0.4, ease: 'power2.out', }, '-=0.4' ) Thanks
GSAP Helper Posted May 30, 2023 Posted May 30, 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 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/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.
Akash Ranjan Posted May 30, 2023 Author Posted May 30, 2023 Here is the codepen demo but I am unable to replicate this issue in codepen because codepen always refreshes from the top of the page. My issue comes when the page refresh from the middle of the web page. See the Pen gOBJQLB by akashrwx (@akashrwx) on CodePen. I can show the issue in a video though https://drive.google.com/file/d/1YXcZN7psGlehMvishH5_RaxUtmceS4V4/view?usp=sharing As you can see the LASER text animates on page load and goes down after scroll. But after we reach the mid of the web page and refresh the page and if the browser keeps the user at the same point and then we scroll up the LASER text stays there and hides and never shows again.
Solution GreenSock Posted May 31, 2023 Solution Posted May 31, 2023 It looks to me like a logic issue in your code - you set up that initial tween to run no matter what, but you actually only want it to run if the page starts out scrolled to the very top (or maybe within the first window.innerHeight)? So currently you've set it up so that the two tweens would fight with each other when the page is scrolled down far enough (one is trying to fade it in and the other is scrubbing a timeline animation of that same element's opacity, etc. Wouldn't a conditional logic wrapper suffice?: See the Pen oNarvpL?editors=0010 by GreenSock (@GreenSock) on CodePen. 3
Akash Ranjan Posted May 31, 2023 Author Posted May 31, 2023 I really feel stupid after finding this solution. Thanks alot for the help Jack
GreenSock Posted May 31, 2023 Posted May 31, 2023 No need to feel stupid at all, @Akash Ranjan! That's not how we see things around here. We all have had times where we couldn't see a particular solution at first...and then we think "oh, why didn't I think of that?" - I've been there plenty of times myself. Enjoy the tools. 3
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