Jump to content
GreenSock

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

Conditional repeat of tweens

Go to solution Solved by Diaco,

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

 

Trying to get a conditional 'repeat' happening with a stagger animation.

 

I want to be able to set a boolean variable (cloudsOn) and if this is true, certain tweens will replay. If it is off, the tweens will not replay.

 

I've managed to get this working in other more custom javascript ways (thanks to help on this forum), but wanted to see if there was a simple way using a stagger loop and onComplete to get this happening.

 

I will post a CodePen but this may be enough to check if it is a simple fix. Thanks.

// five .cloud elements in my SVG
var cloud = document.querySelectorAll('.cloud');

var tlClouds = new TimelineMax();

var cloudsOn = true;

var cloudCheck = function(tween){
    if (cloudsOn){
        console.log(tween); // Successfully logs the individual tweens of the stagger, targeting individual .clouds.
        tween.seek(0);
    }
};

tlClouds
.staggerTo(cloud, 2, {
    cycle:{
        x: [-400, -200, 0, 300]
    },
    onComplete: cloudCheck,
    onCompleteParams: ['{self}']
}, 0.2)
;
Link to comment
Share on other sites

  • Solution

Hi spacewindow :)

 

actually you can't do that in this way ,Timeline control its childs playhead , so you can't seek,pause,play or restart timeline child separately .

  • Like 1
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.

×