Jump to content
GreenSock

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

Animate multiple width in a single animation

Recommended Posts

Hi there,

 

I'm wondering if is possible to load an animation with different width and a small delay each time the width gets bigger.

 

For example:

 

This is the original code:

 

The css for the <div cortana_blurb> is set to width: 0;

 

MU.showBlurb = function(){
TweenMax.to(cortana_blurb, .15, {width: 34,  ease:Linear.easeNone}), .4;
TweenMax.to(cortana_blurb, .15, {width:64, ease:Linear.easeNone, delay:.4 });
TweenMax.to(cortana_blurb, .15, {width:111, ease:Linear.easeNone, delay:.8 });
TweenMax.to(cortana_blurb, .15, {width:144, ease:Linear.easeNone, delay:1.2 });
TweenMax.to(cortana_blurb, .15, {width:204, ease:Linear.easeNone, delay:1.6 });
}
 
What I want is to minimize it to one line code like:
 
MU.showBlurb = function(){
TweenMax.to(cortana_blurb, .15, {width: 34, 64, 111, 144, 204, ease:Linear.easeNone}), .4;
}
 
I know it's a trick one, but if there is a way to do it and you guy could help me it will be great.
 
Kind regards,
 
Fernando Fas

 

Link to comment
Share on other sites

Thanks for the clear explanation. 

 

The best way to solve this would be to create an array of all the widths and then loop through that array and create a new tween for each animation to a new width.

 

var tl = new TimelineLite();
var widths = [34, 64, 111, 144, 204];


for (var i = 0; i < widths.length; i++){
  tl.to(".orange", 0.2, {width:widths[i], ease:Linear.easeNone}, i * 0.4)
}
  • Like 3
Link to comment
Share on other sites

Hey Carl,

 

You are a star.

That's exactly what I was looking for.

 

A big thank you to you.

 

\m/

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