Jump to content
Search Community

OnComplete function inits on start of animation with pause parameter

Roman Kovalev test
Moderator Tag

Go to solution Solved by Jonathan,

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

Hey, guys. Continuing to work with my can rotation project. Here is the code: 
 

project.canAnimation = function() {
    var element = $(".text-element");
    var tl = new TimelineMax({paused: true});
    var $bottle = $('.bottle-block');
    var $sub_title = $('.sub-title');
    var $ready_status = $('.ready-status');
    var $share_block = $('.share-section');
    var $share_block_element = $('.share-section li');

    tl.to(element, 0.75,  {y: -200,rotationX: -90, scale: .75, ease:Expo.easeOut})
    .fromTo(element, 0.75, {y: 200,rotationX: 90, scale: .75}, {onComplete: project.statusGenerator(), y: 0, rotationX: 0, scale: 1, ease:Expo.easeOut, immediateRender:false})
    .to($bottle, 1, {y: '-=70'}, 1.75)
    .to($sub_title, 0.75, {opacity: 0}, 1.75)
    .from($ready_status, 1, {opacity: 0, y: 30})
    .staggerFrom($share_block_element, 2, {y: 30, rotationX: 45, transformOrigin:"left 50% -50", opacity: 0, ease: Elastic.easeOut}, 0.25);


    function step_1() {        
        tl.play();
    }
    function step_2() {
    	tl.to(element, 0.75,  {y: -200,rotationX: -90, scale: .75, ease:Expo.easeOut})
    	.fromTo(element, 0.75, {y: 200,rotationX: 90, scale: .75}, {onComplete: project.statusGenerator(), y: 0, rotationX: 0, scale: 1, ease:Expo.easeOut, immediateRender:false})
    }

    $('#generate-status').on('click', function(){
      	if(!$(this).hasClass('step-2')){
    		step_1();
    		$(this).addClass('step-2');
    	} else {
    		step_2();
    	}

    });
}

The problem that onComplete: project.statusGenerator() inits on page load with its related tasks despite the fact that timeline is paused. But I want to make it happen as I want - on complete.  What am I missing?

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