Jump to content
Search Community

How to cancel existing tween before triggering the same tween

brightpixels test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

See basic codepen () hit the "Reveal list" many times rapidly. The repeated tween will eventually create a mess of the list. How to best to deal with this? No real use case for this. In real world scenario, I could just hide the button after the initial click. Am just testing various scenarios.

 

See the Pen EwdjKV by codeload (@codeload) on CodePen

Link to comment
Share on other sites

Hi @brightpixels :)

 

If it were me, I'd use a timeline that could just start over on click. If you want to return a tween on each click like your demo, you'll end up with overwrites. To fix that you could use a .fromTo() tween like this:

 

return TweenMax.staggerFromTo(elm, 1, {opacity: 0, x: -5}, {opacity: 1, x: 0, ease: Back.easeOut.config(4)}, delay);

 

Hopefully that helps. Happy tweening.

:)

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...