Jump to content
Search Community

Passing arguments into delayedCall method?

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

I'm trying to repeat an animation 3 times - for each element that is inside an array. The element will fade in and then fade out.
Here is the code: How do I pass in an argument into the test function via the delayedCall method?

Thank you.

 

animateCaptions(intro){

    let domH1s    = this.generateCaptions(intro),
        stayTime  = 2,
        slideTime = .8,
        currentH1 = 0;

    const tlCaptions = new TimelineLite({delay: 1.7});


    function test(currentH1){

        tlCaptions
            .to(domH1s[currentH1], slideTime, {opacity: 1, autoAlpha: 1})
            .add(function(){
                currentH1 = ++currentH1 % domH1s.length;
            })
            .to(domH1s[currentH1], slideTime, {opacity: 0, autoAlpha: 0})
    };

    for(let i = 0; i < domH1s.length; i++){
        TweenLite.delayedCall(stayTime, test);
    }




    // for(let i =0;i<domH1s.length;i++){
    //     tlCaptions
    //         .to(domH1s[i], .9, {opacity: 1, autoAlpha: 1});
    //     //check to see if we are on the last index:
    //     //i === captions.length-1 -> length = 3 -1 = 2.
    //     //i works: 0, 1 ,2 so i(2) === captions.length-1
    //     if(i+1 === domH1s.length){
    //         tlCaptions.to(domH1s[i], .5, {opacity: 1, autoAlpha: 1})
    //     }else{
    //         tlCaptions.to(domH1s[i], .5, {opacity: 0, autoAlpha: 0, delay: 1.4});
    //     }
    // };

    return tlCaptions;

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