Jump to content
Search Community

Timeline: onComplete, pass timeline to new class

Parrot Puppet test
Moderator Tag

Go to solution Solved by akapowl,

Recommended Posts

Hey Gsap!

I'm looking for a way to create a infinite loop but on every iteration it is a new animation based on a if statement. I had a repeat:-1 called in the timeline with 'random()' utils within the tween, now I'm starting to play around with alt variations on repeat and chose to go a class based function approach.

In the below code snippet I'm looking to pass the instance of timeline, I'm having a bit of trouble trying to find 'tl' onComplete to pass to a new class call

window.addEventListener("load", () => {
	let tl = gsap.timeline({
		onComplete: function () {
			new Anim(this); //how do I pass tl onComplete?
		}
	});
	let start = new Anim(tl);
});

 

thanks for your time!

See the Pen WNoERVE by mr-parrott (@mr-parrott) on CodePen

Link to comment
Share on other sites

  • Solution

 

Hey @mr-parrott

 

Would something like this work for you?

 

window.addEventListener("load", () => {

	function createNew() {
				
		let tl = gsap.timeline();
		tl.eventCallback("onComplete", createNew);
		
		new Anim(tl);		
		console.log(tl)
		
	}
	
	createNew();
	
});

 

 

See the Pen 69280b40e98c9947a89e48fe6587563d by akapowl (@akapowl) on CodePen

 

 

  • Like 5
  • Thanks 1
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...