Jump to content
Search Community

timelinName.restart()

Nan Say 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 All,

 

I am using TimelineLite to play a punch of animation.

I have a timeline and wanted to call a function oncomplete something

 

eg. timelineName = new TimelineLite();

timelineName.pause();

timelineName.to($('#someID"), 1, {display: 'block', onComplete: start() });

 

function start() {

  timelineName.restart();

}

 

 

Its cause the error "Uncaught TypeError: Cannot read property 'restart' of undefined"

 

Do I miss something?

 

 

Thanks, 

Link to comment
Share on other sites

Hi Nan Say,

 

onComplete is being called when you create your timeline and not when the animation is actually completed. You need to add a reference to your function without the parentheses. 

 

var tl = new TimelineLite();
tl.to(".box", 2, { x: 500, onComplete: start });

function start() {
  tl.restart();
}

See the Pen jExzJg by osublake (@osublake) on CodePen

  • Like 3
Link to comment
Share on other sites

Hi Nan Say  :)

 

try this :

var timelineName = new TimelineLite();
timelineName.to("#someID", 1, {........... , onComplete:start });

function start() {
  timelineName.restart();
}

or another shortest way : 

var timelineName = new TimelineLite({ onComplete: function(){ this.restart() } });
timelineName.to("#someID", 1, {............});

edit : Ooops ... OSUblake already answered 

  • Like 2
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...