Jump to content
Search Community

TimelineMax .How to add Complete Event in each motion

ylylsheep test
Moderator Tag

Go to solution Solved by Carl,

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

I am come from china. my english is poor , so...

 

 

my code 

// JavaScript Document
tl=new TimelineMax( 
	{ 
		onComplete:function()
		{	
			TweenMax.to($("#divId"),.7,{delay:.7,opacity:0,ease:Linear.easeNone,onComplete:function()
				{
					//my event	
				}
			})			
		}
	})
tl.to($("#divId"),.5,{left:-200})
.to($("#divId"),1,{opacity:0})	
.to($("#divId"),2,{top:260})

I want to do it like this:

add “onComplete” event when each motion complete

tl=new TimelineMax( 
	{ 
		onComplete:function()
		{	
			TweenMax.to($("#divId"),.7,{delay:.7,opacity:0,ease:Linear.easeNone,onComplete:function()
				{
					//my event	
				}
			})			
		}
	})
tl.to($("#divId"),.5,{left:-200,onComplete:function(){/*do something*/}})
.to($("#divId"),1,{opacity:0,onComplete:function(){/*do something*/}})	
.to($("#divId"),2,{top:260})

.to($("#divId"),1,{opacity:0,onComplete:function(){/*do something*/}})    

 

 

 

 

 

 

//------------------------------------
i just did it like this for work,

TweenMax.to($("#divId"),1,
{
	onComplete:function()
	{
		TweenMax.to($("#divId"),1,
		{
			onComplete:function()
			{
				TweenMax.to($("#divId"),1,
				{
					onComplete:function()
					{
						
					}
				})
			}
		})
	}
})
Link to comment
Share on other sites

I found this, add it is working

addCallback ( callback:Function, position:*, params:Array, scope:* ) : TimelineMax
Inserts a callback at a particular position.

my code:

tl=new TimelineMax( )
tl.to($("#divId"),.5,{left:-200})
.to($("#divId"),1,{opacity:0})	
.to($("#divId"),2,{top:260})

tl.addCallback(function(){/*do something*/},.5)
tl.addCallback(function(){/*do something*/},1.5)

but I am still want to use like:    

 

.to($("#divId"),1,{opacity:0,onComplete:function(){/*do something*/}})  

 

because if i changed motion time,I must have to change callback time again。

Link to comment
Share on other sites

  • Solution

[docs id=js.TweenLite.to()" linkText="TweenLite.to]

 

Welcome to the forums.

 

You can add an anonymous onComplete callback to each tween if you like. Maybe you have a syntax error in first example.

 

var tl = new TimelineLite();


tl.to("#redBox", 1, {
    x: 550,
    onComplete: function() {
      TweenMax.set("#redBox", {
        opacity: 0.5,
        scale: 0.5
      })
    }
  })
  .to("#blueBox", 1, {
    x: 550,
    onComplete: function() {
      TweenMax.set("#blueBox", {
        opacity: 0.5,
        scale: 0.5
      })
    }
  }, "-=0.5")

http://codepen.io/GreenSock/pen/VLVOXN?editors=001

Also, using addCallback you do not need to set the time with the position parameter, you can do this

var tl = new TimelineMax();


tl.to("#redBox", 1, {x: 550})
  .addCallback(function() {
    TweenMax.set("#redBox", {opacity: 0.5, scale: 0.5})
})


.to("#blueBox", 1, {x: 550})
  .addCallback(function() {
    TweenMax.set("#blueBox", {opacity: 0.5, scale: 0.5})
})
 
and each time you change duration of tweens, you do not have to move the callbacks

 

http://codepen.io/GreenSock/pen/KprLem?editors=101

  • Like 3
Link to comment
Share on other sites

Welcome to the forums.

 

You can add an anonymous onComplete callback to each tween if you like. Maybe you have a syntax error in first example.

 

var tl = new TimelineLite();


tl.to("#redBox", 1, {
    x: 550,
    onComplete: function() {
      TweenMax.set("#redBox", {
        opacity: 0.5,
        scale: 0.5
      })
    }
  })
  .to("#blueBox", 1, {
    x: 550,
    onComplete: function() {
      TweenMax.set("#blueBox", {
        opacity: 0.5,
        scale: 0.5
      })
    }
  }, "-=0.5")

See the Pen VLVOXN?editors=001 by GreenSock (@GreenSock) on CodePen

Also, using addCallback you do not need to set the time with the position parameter, you can do this

var tl = new TimelineMax();


tl.to("#redBox", 1, {x: 550})
  .addCallback(function() {
    TweenMax.set("#redBox", {opacity: 0.5, scale: 0.5})
})


.to("#blueBox", 1, {x: 550})
  .addCallback(function() {
    TweenMax.set("#blueBox", {opacity: 0.5, scale: 0.5})
})
 
and each time you change duration of tweens, you do not have to move the callbacks

 

See the Pen KprLem?editors=101 by GreenSock (@GreenSock) on CodePen

 

 

Thank you very much!

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