andrewandopen Posted April 5, 2023 Share Posted April 5, 2023 I have a series of panels which are scrolling into my viewport when certain buttons are clicked. At the end of the flow, I would like to have the option of scrolling backwards (essentially sliding the most recent panel out of view again). Is there a way to achieve this? Apologies, I am running this project locally at the moment Link to comment Share on other sites More sharing options...
GSAP Helper Posted April 5, 2023 Share Posted April 5, 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. Link to comment Share on other sites More sharing options...
andrewandopen Posted April 5, 2023 Author Share Posted April 5, 2023 @GSAP Helper I've just created a minimal demo of what I mean below. So the "scroll in to view" button will scroll my div into view. I would like the "scroll out of view" button to reverse this. https://codesandbox.io/s/busy-danny-6h6wvg?file=/src/App.js Link to comment Share on other sites More sharing options...
mvaneijgen Posted April 5, 2023 Share Posted April 5, 2023 Hi @andrewandopen I've forked your codesandbox and add some logic to check if it has already scrolled and if so reverse the scroll to 0 (you could easily swap that out for another number, like the recorded scroll distance where the user was when clicking the button). I don't use react, so I it is now more a toggle of the same button, but that could also be changed to the other button. https://codesandbox.io/s/naughty-cerf-irud6z Or you can create the animation outside of the logic give it a variable name, set it to paused and reversed and then check if the animation has already played and then toggle its logic. This should work, but react is fighting me and I can't figure out what it wants. Hope it helps and happy tweening! https://codesandbox.io/s/heuristic-sky-w00w4r?file=/src/App.js 2 Link to comment Share on other sites More sharing options...
andrewandopen Posted April 5, 2023 Author Share Posted April 5, 2023 Thanks for your response @mvaneijgen. So, I'm using refs so that when the button is clicked it scrolls the associated div into view (as opposed to using fixed values), so reverse the scroll to 0 won't work as it will scroll right to the top of the page and bypass the div i want to stop on. Is there a way to scroll the panel back down without using a fixed value? Link to comment Share on other sites More sharing options...
Rodrigo Posted April 5, 2023 Share Posted April 5, 2023 Hi, On top of @mvaneijgen's great advice, we strongly recommend using GSAP Context when using GSAP in a React environment: https://greensock.com/docs/v3/GSAP/gsap.context() Also take a look at the resources in this page: I forked the example by Mitchel and added GSAP Context to the mix: https://stackblitz.com/edit/vitejs-vite-vxpma3?file=src%2FApp.jsx&terminal=dev Hopefully this helps. Let us know if you have more questions. 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