greensock / GSAP

GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web

Home Page:https://gsap.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Negative gsap.ticker.time and timelines not playing

lk77 opened this issue · comments

Hello,

when the system date and time changes,
gsap stop playing animations,

the callback passed to gsap.ticker.add is not called anymore and the animations are completely frozen,

gsap.ticker.time is negative for me : around -17000

The fix for now seems to be using performance.now :

// We remove the default listener
gsap.ticker.remove(gsap.updateRoot);

// we save the current time since window has loaded
const startTime = performance.now();

const update = () => {
    // We update the number of seconds manually
    gsap.updateRoot((performance.now() - startTime) / 1000)

    // We register the next animation frame
    requestAnimationFrame(update);
};

update();

Do you have any idea why ?

thank you

Ah, that's because Date.now() would report as less than it would previously. We use Date.now() instead of performance.now() for two reasons:

  1. It performs much better (faster).
  2. It's more widely compatible (old browsers)

However, I've added code to the next release which should sense that condition and recover from it. You can preview it here:
https://assets.codepen.io/16327/gsap-latest-beta.min.js

Better?

@jackdoyle thanks, i will try it

edit: i've tried it and it works fine, the animations keeps playing

Resolved in the latest release.

@jackdoyle thanks, i will update