Jump to content
Search Community

reverse cross-dissolve and scale

pfash test
Moderator Tag

Go to solution Solved by PointC,

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

Hi All,

Beginner here. I'm hacking code given to me on this forum by PointC.

 

I need to know how to reverse the scaling/cross-dissolving in my codpen demo:

...by clicking on the red box a second time.

 

IOW: you click on the red box once to have it dissolve into the blue box and scale up...and then you click on the red box again and it all goes in reverse. That second part is my question.

 

NOTE: This demo is supposed to have the red box on top of the blue box (so the red color smoothly transitions into blue) but I didn't have time to figure that out for this codepen demo and it's not critical to my question.

 

Another concern: the scaling up (zooming larger) and cross-dissolving is not as smooth as I expected it'd be. You can see the blue box flash a bit. Any ideas why?

 

Thanks much!

 

See the Pen aprmxq by pfash (@pfash) on CodePen

Link to comment
Share on other sites

  • Solution

Hi again pfash :)

 

Looks like you're starting to dig into GSAP a bit further.

 

As I mentioned in your other thread, we can move those tweens into a timeline which can then be played/reversed on click. A problem with your current setup is the click listener is on the red box, but the red box tweens to an autoAlpha of 0 (opacity:0, visibility:hidden) so you can't click it again to reverse everything. I'd recommend putting the boxes into a parent and place the click event listener on the parent. Here's a fork of your pen with some revisions:

 

See the Pen bgyoMg by PointC (@PointC) on CodePen

 

One other note. Your tween target is currently written like this:

TweenMax.to(redBox, 2, {autoAlpha:0}); // redBox is a variable that hasn't been declared

You should actually do one of these:

// declare the variable and then tween it
var redBox = $("#redBox");
TweenMax.to(redBox, 2, {autoAlpha:0});

// or simply add the ID or class directly into the tween
TweenMax.to("#redBox", 2, {autoAlpha:0});

Hopefully that helps.

 

Happy tweening.

:)

  • Like 2
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...