Tony_ton Posted February 28 Share Posted February 28 Hello, I wanted to ask - is it possible to run the from() animation on an element after the to() animation has worked on it? Here's an example, first I run the to() animation: let hideSearchTl = gsap.timeline({ defaults: { ease: 'cubic-1', duration: 0.2, overwrite: true, }, }), elements = $('selector'); hideSearchTl.to(elements, { width: 0, autoAlpha: 0, padding: 0, }); Then, when performing certain actions, I want to return the element with a from() animation: hideSearchTl.from(elements, { width: 0, autoAlpha: 0, padding: 0, }); Using reverse() is not entirely suitable (or I don’t know how to use it) because it “reverses” the easy property. I need easy the same as in to() animation. As far as I understand the complexity in the filled style attribute, I just can’t come up with a solution. Link to comment Share on other sites More sharing options...
GSAP Helper Posted February 28 Share Posted February 28 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...
Solution Rodrigo Posted February 28 Solution Share Posted February 28 Hi @Tony_ton and welcome to the GSAP Forums! Nothing wrong with the code you're posting, GSAP is doing what's supposed to, the issue stems from not understanding exactly how from() and fromTo() instances work. A from instance takes the element you're tweening from the value you're passing in the config to the value it has before that instance is rendered. So if you have an element with opacity: 1 as is current value and you use a from instance with opacity: 0, GSAP tweens the opacity value from 0 to the value it had before, that is 1. But if you have an element with opacity 0 and you create a from() instance with opacity 0, GSAP takes the element from the value you passed in the config (0) to the value it had before (also 0). GSAP is doing what is supposed to, the problem is that you're telling GSAP tween the opacity value from 0 to 0, so nothing happens visually but GSAP is actually doing that. If you want your element back to opacity 1 then just use another to instance: hideSearchTl.to(elements, { width: someValue, autoAlpha: 1, padding: someValue, }); Hopefully this clear things up. Happy Tweening! 1 Link to comment Share on other sites More sharing options...
Tony_ton Posted February 29 Author Share Posted February 29 Hello @Rodrigo, thanks for your answer) Perhaps it’s better to reconsider my approach to animation 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