Jump to content
GreenSock

Pusher

Cue function on Complete in TimelineMax

Recommended Posts

Hi there,

 

Sorry if this is a stupid question.

 

I am trying to pause a function and only start it when an onComplete happens in TimelineMax. The function works perfectly except that when it plays it is off screen because it is firing as soon as the animation starts.

<script>
var tl = new TimelineMax ()
tl
.from("#txt1", 1, {right:-280, ease:Power2.easeInOut}, "+=4")
.from("#counter", 1, {right:-280, ease:Power2.easeInOut, onComplete: startCounter})
.from("#txt2", 1, {right:-280, ease:Power2.easeInOut})
.from("#logo", 1, {top:250, ease:Power2.easeInOut})
.from("#tag", 1, {right:90, autoAlpha:0, ease:Power2.easeInOut})


var distance = {counter:0}, scoreDisplay = document.getElementById("counter");
function add() {
TweenMax.to(distance, 1, {counter:"+=200", roundProps:"counter", onUpdate:updateHandler});
}
function updateHandler() {
scoreDisplay.innerHTML = distance.counter;
}
add();

distance.pause()

function startCounter() {
distance.play() 
}
</script>

Thanks for any help,

 

Phil

Link to comment
Share on other sites

Hi, 

 

Its a little difficult to follow your description. I think the big problem is that you are trying to play and pause distance like

 

distance.play()

distance.pause()

 

distance is just an object {counter:0} it doesn't have play or pause methods.

 

my only guess without seeing a working codepen demo is that this

.from("#counter", 1, {right:-280, ease:Power2.easeInOut, onComplete: startCounter})

should be changed to

.from("#counter", 1, {right:-280, ease:Power2.easeInOut, onComplete: add})

and you should not call add() directly where you are doing

add(); 
distance.pause();

If you need more help please provide a CodePen demo. It will alleviate the guess work.

  • Like 1
Link to comment
Share on other sites

Hi Carl,

 

Thank you for the advice. Codepen is brilliant! I will definately use it from now on!

The above seems to have worked. Except that the counter has already played by the time it gets to the stage.

 

Is there a way to pause distance?

 

My codepen is here if you can still help!

 

See the Pen GpjgpL by phillip_vale (@phillip_vale) on CodePen

 

Thanks so much,

 

Phil

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