Jump to content
Search Community

Animate multiple width in a single animation

fernandofas test
Moderator Tag

Go to solution Solved by Carl,

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

  • Solution

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

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