kbatchu Posted February 28 Share Posted February 28 Hello, I am trying to show/hide different text as the user scrolls. However, I noticed that when I scroll using the mouse scroll wheel, the entire text (e.g. txt2 in the codepen example) is not displayed. It shows partial text depending upon the amount of scroll. I understand this is how ScrollTrigger works, but how do I make sure that when the user scrolls, the entire text of 'txt2' or 'txt3' or 'txt4' is displayed at a time, not partial text. Ideally, I want to create the 'fade-in', 'fade-out' effect for each text variable i.e. txt2, txt3 etc. Thanks, Kiran See the Pen mdgbYJw by kbatchu (@kbatchu) on CodePen Link to comment Share on other sites More sharing options...
Solution mvaneijgen Posted February 28 Solution Share Posted February 28 As you've stated that is indeed how ScrollTrigger works. But there is another plugin that sounds like what you're looking for have you seen the Observer plugin https://gsap.com/docs/v3/Plugins/Observer/ With the plugin you can watch for scroll events and then do some logic based on that. Here is a example that tweens to labels on a timeline and it just animates the previous of next label on a timeline. To implement this in your project you'll just have to put labels in your timeline where you want the scroll to stop. Hope it helps and happy tweening! See the Pen GRzrPPy by mvaneijgen (@mvaneijgen) on CodePen And here an example that mixes normal scroll with the Observer plugin See the Pen oNQPLqJ by GreenSock (@GreenSock) on CodePen Just going to put this here: See the Pen dyLbBom?editors=0011 by mvaneijgen (@mvaneijgen) on CodePen 1 Link to comment Share on other sites More sharing options...
kbatchu Posted February 29 Author Share Posted February 29 Thank you so much for the examples. I think I need what you created in the second example where normal scroll is mixed with Observer plugin. There is a lot to unpack here for me. Your third example (with my use case) helped me understand how Observer by itself works. GSAP is a wonderful bag of tricks. 2 Link to comment Share on other sites More sharing options...
kbatchu Posted February 29 Author Share Posted February 29 I am still wrapping my head around 'Observer' so I apologize for this question. In your third example (with my use case), I see "onDown: (self) => tweenToLabel(tl.previousLabel())". I would expect that when I am scrolling the mouse wheel 'down', it should go the 'next' label and the opposite in "onUp". How does this work? Thanks, Link to comment Share on other sites More sharing options...
mvaneijgen Posted February 29 Share Posted February 29 This might be reversed and you should set it to your preference. I'm on a Mac and have set my logic to be the same as on a phone when you scroll and move your fingers up on the track pad the page moves in that same direction. Again, you have to set this what feels right for your target audience. Link to comment Share on other sites More sharing options...
kbatchu Posted February 29 Author Share Posted February 29 Got it. Thank you. Link to comment Share on other sites More sharing options...
kbatchu Posted February 29 Author Share Posted February 29 @mvaneijgen So I tried to use the mixed observer and scrolling method to my use case. I am running into a couple of issues 1) When I mouse-wheel scroll down, the tween jumps from 'txt1' to 'txt4' directly. I don't see 'txt2' and 'txt3' 2) When I mouse-wheel scroll up (reverse direction), the tween is stuck at 'txt4' and does not display the text elements in the reverse order. I think I am going wrong in the 'function tweenToLabel(direction)' but cannot figure out what. Do you mind taking a look? I updated my original codepen sample. Thank you. Link to comment Share on other sites More sharing options...
GSAP Helper Posted March 1 Share Posted March 1 Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates 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. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer. See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo: 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...
kbatchu Posted March 1 Author Share Posted March 1 I fixed the code in my minimal demo (link in my first post above). It works as expected now. 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