Jump to content
Search Community

looping animation a set number

emb69 test
Moderator Tag

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

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

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