Jump to content
GreenSock

onedayitwillmake

Feature request / Maybe it exist already?

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 I'm wondering if this already exist in TweenMax, or if not, if it's possible to request for a feature here.

 

Sometimes when working on something, you might want to have an update loop temporarily (say mousedown, until mouse up). The way to do that in JS would be to create a request animation frame, and then kill it later etc etc.

 

However since TweenMax is already running one in the background, I was wondering if it was possible to hook into it somehow. Taking advantage of the nice, remove / pause features TweenMax provides

 

I imagine something like, (or whatever you guys see fit!)

var updateReference = TweenMax.onEnterFrame(scope, myFunction);
updateReference.pause();
updateReference.resume();
updateReference.remove();
Link to comment
Share on other sites

Sure, that's exactly what the TweenLite.ticker is for. See http://api.greensock.com/js/com/greensock/core/Animation.html#ticker for docs. 

 

It's smart to tap into this because not only does it ensure that all your stuff perfectly synchronizes with the core engine's updates, but you also get all the benefits of GSAP's workarounds of bugs in various browsers. For example, there are problems with iOS's requestAnimationFrame functionality in certain scenarios and some browsers don't even support requestAnimationFrame at all - GSAP automatically falls back to setTimeout() in those cases. It'd be a pain if you had to do all that stuff yourself. 

TweenLite.ticker.addEventListener("tick", yourFunction);

It's that easy. And then of course you can removeEventListener() too.

 

Is that what you were looking for? 

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