Jump to content
GreenSock

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

looping animation a set number

Recommended Posts

Hello,

 

Working on an animation which needs to repeat (loop) a number (7) of times. I've placed all the animation into one function (timeline):

function forward () {

var tl = new TimelineLite();

tl.to(one, 0.75, {css:{rotation:".16rad" },ease:Linear.easeNone} );

tl.to(one, 0.75, {css:{rotation:"0 rad" },ease:Linear.easeNone} );

tl.to(two, 0.55, {css:{rotation:"-.14rad" },ease:Linear.easeNone});

tl.to(thr, 0.50, {css:{rotation:"-.13rad" },ease:Linear.easeNone});

tl.to(fou, 0.45, {css:{rotation:"-.12rad" },ease:Linear.easeNone});

tl.to(fiv, 0.40, {css:{rotation:"-.12rad" },ease:Linear.easeNone});

tl.to(six, 0.35, {css:{rotation:"-.11rad" },ease:Linear.easeNone});

tl.to(six, 0.30, {css:{rotation:"0 rad" },ease:Linear.easeNone} );

tl.to(fiv, 0.25, {css:{rotation:"0 rad" },ease:Linear.easeNone} );

tl.to(fou, 0.20, {css:{rotation:"0 rad" },ease:Linear.easeNone});

tl.to(thr, 0.15, {css:{rotation:"0 rad" },ease:Linear.easeNone});

tl.to(two, 0.14, {css:{rotation:"0 rad" },ease:Linear.easeNone});

}

 

Is there a way to repeat the animation without creating another functions? As well as ending the repeat at a set number of times?

 

If this has been asked before, pardon the repeative topic.

Link to comment
Share on other sites

Hi and welcome to the forum!!

 

The most simple way is to use repeat property, but for that you have to use TimelineMax, since repeat is not a property of TimelineLite. Take a look at the api reference.

 

You said that the idea is to repeat that timeline 7 times, so it would be something like this:

 

function forward(){
   var tl = new TimelineMax({repeat:6});
   tl.to(one, 0.75, {css:{rotation:".16rad" },ease:Linear.easeNone} );
   .....
 tl.to(two, 0.14, {css:{rotation:"0 rad" },ease:Linear.easeNone});
}

Keep in mind that the code above will play the tween 7 times, since it will play one time and repeat six times.

 

Hope this can help,

Cheers,

Rodrigo.

  • Like 3
Link to comment
Share on other sites

Rodrigo,

 

Thanks for the help and advise.

 

Cheers,

Ed.

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