Jump to content
Search Community

wait for animation

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

Hi,

 

I have some animation that i want to run, then do some other stuff, but the other stuff is running and so the animation isn't seen?

 
      // animate and hide current active item

      var old_item = $('#'+parent+' li.active ul li' );

      var tl = new TimelineLite();



      tl.to(old_item,1,{width:"0px",height:"0px", alpha:0, ease:Elastic.easeInOut});



      // remove active class and add to new item button

      $('#'+parent+' li.active').removeClass('active');

      $('#'+id).addClass('active');

How do I ensure any JS/JQuery following a timeline tween animation waits for the animation before executing?

 

Thanks,

1DMF.

Link to comment
Share on other sites

Hi,

 

Use an onComplete callback in the timeline, then when the timeline finishes the callback gest executed:

var old_item = $('#'+parent+' li.active ul li' );

var tl = new TimelineLite({onComplete:yourFunction});

tl.to(old_item,1,{width:"0px",height:"0px", alpha:0, ease:Elastic.easeInOut});

// remove active class and add to new item button

function yourFunction()
{
  $('#'+parent+' li.active').removeClass('active');

  $('#'+id).addClass('active');  
}

Like that the code will execute once the timeline is completed.

 

Rodrigo

Link to comment
Share on other sites

Hi,

 

I've tried this..

 

       
var tl = new TimelineLite({onComplete:clearActive(active)});
tl.to(old_title,1,{y:"-=1000", alpha:0, ease:Elastic.easeInOut});
 
function clearActive(active)
{

        alert("hi");
    // remove old active
    active.removeClass('active');   
    
}

 

I get the alert before the animation runs?

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