Jump to content
Search Community

How to use useRAF with gsap.timeline()

paulvancity test
Moderator Tag

Recommended Posts

Hey Paul, welcome to the GreenSock forums.

 

GSAP automatically uses RAF under the hood. If you want to tap into the same RAF cycle as GSAP, use GSAP's ticker. In most cases just using tweens and timelines can animate what you want to animate though.

 

More details about your situation would be helpful.

  • Like 1
Link to comment
Share on other sites

2 hours ago, ZachSaucier said:

Hey Paul, welcome to the GreenSock forums.

 

GSAP automatically uses RAF under the hood. If you want to tap into the same RAF cycle as GSAP, use GSAP's ticker. In most cases just using tweens and timelines can animate what you want to animate though.

 

More details about your situation would be helpful.

I want to do useRAF(false)

Link to comment
Share on other sites

Very important question: WHY do you want to do this? If your goal is to have the time progress so that when the tab is re-activated, the animations look like the time has elapsed, you can simply disable lagSmoothing like gsap.ticker.lagSmoothing(false). 

 

If you literally want the animations to continue at 60fps, that's a total waste of resources and frowned upon in the industry because you're eating up users' battery and CPU resources on a tab that's not even visible. 

 

Also keep in mind that most browsers drop requestAnimationFrame and even setTimeout()/setInterval() calls significantly in tabs that are inactive. That's a GOOD thing. 

 

If this hasn't helped, please do tell us the "why" behind your request because I suspect there's a better solution. I'd strongly recommend not forcing all your animations to continue running at full speed in inactive tabs. 

  • Like 3
Link to comment
Share on other sites

1 hour ago, GreenSock said:

Very important question: WHY do you want to do this? If your goal is to have the time progress so that when the tab is re-activated, the animations look like the time has elapsed, you can simply disable lagSmoothing like gsap.ticker.lagSmoothing(false). 

 

If you literally want the animations to continue at 60fps, that's a total waste of resources and frowned upon in the industry because you're eating up users' battery and CPU resources on a tab that's not even visible. 

 

Also keep in mind that most browsers drop requestAnimationFrame and even setTimeout()/setInterval() calls significantly in tabs that are inactive. That's a GOOD thing. 

 

If this hasn't helped, please do tell us the "why" behind your request because I suspect there's a better solution. I'd strongly recommend not forcing all your animations to continue running at full speed in inactive tabs

Awesome thank you. I want to do this because I don’t want all my animations backing up when they switch back to the tab, it’s a game with a series of icons coming out every few seconds, and when i switch back, it shows all the icons together and it just looks ugly. 

Link to comment
Share on other sites

2 minutes ago, paulvancity said:

it’s a game with a series of icons coming out every few seconds, and when i switch back, it shows all the icons together and it just looks ugly. 

Why not throttle your game to not keep spawning icons every few seconds when the tab isn't visible?

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Hi guys,

 

just wondering how I can implement this. Here is my code

 

Would I just do gsap.timeline().ticker.lagSmoothing(false) ?

 

        var tl = gsap.timeline();
        tl.to('#'+xp_el, {top:"-=25", duration: 1.5, ease:"Power4.easeOut"}).
        to('#'+xp_el, {opacity:0});
Link to comment
Share on other sites

No, that code is incorrect. I already provided the code in my previous post: 

gsap.ticker.lagSmoothing(false)

By the way, you could save yourself some typing by using the shorter string-based ease syntax. The .easeOut is the default anyway, so...

// old/long
ease:"Power4.easeOut"

// new/short
ease:"power4"

Happy tweening!

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 7 months later...
1 hour ago, _marta said:

sets lagSmoothing to false will this affect all of their timelines?

Yes.

 

1 hour ago, _marta said:

Is there a way to just set this property to a specific one?

Not really. To do that you'd need to have two instances of GSAP running which is possible but probably not worth your effort I'd guess.

  • Like 1
Link to comment
Share on other sites

1 hour ago, _marta said:

Is there a way to just set this property to a specific one?

That'd be super weird - one of the big benefits of GSAP is that everything remains perfectly synchronized. If you have lagSmoothing set differently on various timelines, it'd totally throw that off. And then what'd you do if you had one timeline nested inside another and they have different settings? It could get very messy. Sorta like if you had a clock where the "seconds" hand ran at a different rate than the "minutes" hand which ran at a different rate than the "hours" hand. I can't imagine a scenario where you'd want lagSmoothing on one animation but not another - can you explain a scenario where that'd be helpful? 

  • Like 2
Link to comment
Share on other sites

 

1 minute ago, GreenSock said:

That'd be super weird - one of the big benefits of GSAP is that everything remains perfectly synchronized. If you have lagSmoothing set differently on various timelines, it'd totally throw that off. And then what'd you do if you had one timeline nested inside another and they have different settings? It could get very messy. Sorta like if you had a clock where the "seconds" hand ran at a different rate than the "minutes" hand which ran at a different rate than the "hours" hand. I can't imagine a scenario where you'd want lagSmoothing on one animation but not another - can you explain a scenario where that'd be helpful? 

 

I wanted to have just a specific timeline that would keep running when I switched tabs, on just one specific situation. All of the other timeline would run normally.

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