Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
mikeebee

Stopping a Tween overwriting another

Recommended Posts

Hi all, 

 

I have a mouseover and a mouseout effect using TweenMax, It affects the y value. Works great. On a click event, I then use TimelineMax to animate various elements.

 

To look right, the start of the click animation relies on the mouseover tween being in it's most complete state, with the y value at it's peak.

 

So if you...

  1. hover
  2. leave your cursor in place
  3. and then click.

It looks perfect.

 

The issue I'm having is that if you...

  1. click
  2. quickly move your cursor away

the mouseout tween appears to overwrite the y value and the colour starts to drop out of position and doesn't fill the full box.

 

I've tried a few methods of stopping the mouseout tween cancelling the click tween but I'm stumped.

 

The items don't reset after being clicked (they'd usually change the page) but there are few to click on to test ;)

 

Basically, I need the mouseout animation to not run if you have clicked.

 

Any help will be appreciated.

 

Cheers,

Mike 

See the Pen RPGGyM?editors=101 by anon (@anon) on CodePen

Link to comment
Share on other sites

Thinking about this, I bet there is a better way to do this using Timeline properly.

 

1. Mouseover - Assuming the stationary position is point A, play timelime to point B

2. Mouseout - reverse timeline from point B to point A

3. Click - play to point C regardless of point. So this could be anywhere between point A and B and it would just play smoothy to point C.

 

Does that make sense? Would someone be able to help me with that, if it's a good idea of course!

 

Thanks

Link to comment
Share on other sites

Hi mikeebee  :)

 

pls try something like this :

$(".box").each(function(){
var tl = new TimelineMax({paused:true});
tl.to($(this),0.5,{backgroundColor:'green'})
  .add("over")
  .to($(this),0.5,{backgroundColor:'red',scale:0.7})
  .add("click");
 this.animation = tl;
});

$(".box").hover(over, out);
function over(){ this.animation.tweenTo("over") };
function out(){ this.animation.reverse() };

$(".box").click(function(){ this.animation.tweenFromTo("over", "click") });

pls check this out : 

See the Pen oXzZJo by MAW (@MAW) on CodePen

  • Like 1
Link to comment
Share on other sites

This works great! I have another question...

 

Is there a way to reverse all timelines except the one you're interacting with?

 

See this demo, you can see the code I tried at the bottom. The ideal outcome would be that you click one, then you click another and the one that was clicked and animated goes back to it's original state.

 

See the Pen oXzdqW by anon (@anon) on CodePen

 

Thanks!

Link to comment
Share on other sites

you can do something like this :

$('.box').not(this).each(function(){this.animation.reverse()})
Link to comment
Share on other sites

Yeah that's cracked it!
 
Could you explain what

this.animation = tl;

This part does please? 

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.
×