Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
cbg

How can I execute a Javascript function in my timeline?

Recommended Posts

Hi there, I'm using TimelineMax and getting some great results. I'm getting quite proficient with using the Timeline to animate various elements on the page. I've found a script called Typed.js that I've been able to run independently of the Timeline perfectly but I'm unsure of how to get it to play within the timeline? I know there are some callback features but my Javascript isn't great!

 

http://www.mattboldt.com/demos/typed-js/

Link to post
Share on other sites

What exactly is it that you want to do?

 

To answer the question of: "How can I execute a Javascript function in my timeline". A dive into the docs will show you several ways:

 

https://greensock.com/docs/#/HTML5/Sequencing/TimelineMax/add/

https://greensock.com/docs/#/HTML5/Sequencing/TimelineMax/addCallback/

https://greensock.com/docs/#/HTML5/Sequencing/TimelineMax/call/

https://greensock.com/docs/#/HTML5/Sequencing/TimelineMax/eventCallback/

https://greensock.com/docs/#/HTML5/GSAP/TweenLite/delayedCall/

 

From looking at this Typed.js I imagine you could do something like:

var tl = new TimelineMax()

tl.to(...)
tl.call(function(){ Typed.new('.element', {strings: ["First sentence.", "Second sentence."],typeSpeed: 0}) } ) );
tl.to(...)

Worth mentioning that there are loads of ways to achieve a type writer effect using just GSAP, if you're interested.

 

https://greensock.com/forums/topic/11361-typewriter-effect/

 

Does any of that help?

 

:)

  • Like 1
Link to post
Share on other sites

Thanks Dipscom.

 

I was able put the script into a variable and then use the onComplete parameter in my timeline to play the variable in the end. Now I've learnt how I'll be able to reuse this method!

Link to post
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.

×