Jump to content
Search Community

delayedCall does not keep time if paused with visibility API

Rob 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 Guys,

The Timelines and delayedCalls method seems to forget time if they are paused when using the visibility API, when a tab loses visibility i'm setting the tween's timescale to 0 and pausing the audio.


The audio play calls are trigger on a Timeline, I'm then using delayedCall to stop the audio after a certain duration.


I have setup an example here http://jsfiddle.net/robaldred/nj9pY/

(requires sound& used fiddle because i needed to link multiple externals and don't have pen pro)


On load, sound will play through nicely. All timelines and delayed calls work as expected.


However if you switch to another tab for 30 seconds or so at some point during a playing clip.


When when you return to the tab it really screws up the timeline and the delayedCall, it's like the play head jumps forward when setting timeScale back to 1.


This only appears to happen when using visibility API callbacks. Something to do with RAF not being called when a tab is hidden?


Any thoughts?


Appreciate your time.


Link to comment
Share on other sites

Yep, that's exactly how it's supposed to work. Remember, one of the benefits of using requestAnimationFrame is that it "powers down" (well, just throttles back to something like 2fps) when the tab is inactive which saves power and CPU cycles. If you don't want that behavior, you can tell GSAP to use a regular setTimeout() to drive its updates instead by doing this:


Does that help? 

  • Like 1
Link to comment
Share on other sites

Hi Rob,


Have you tried this solution suggested by Jonathan?:




Also you could give this option (also suggested by Jonathan) a shot, it works with the engine's ticker event:





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