tailbreezy Posted February 24, 2021 Share Posted February 24, 2021 var tl = gsap.timeline() .to('.box', { x: 200}) console.log(gsap.globalTimeline.duration()) // ~1.281 console.log(gsap.exportRoot().duration()) // ~1.281 console.log(tl.duration()) // 0.5 I wonder where the extra 0.70-0.80s come from in exportRoot and globalTimeline. See the Pen 638b1c9b5c499e1e455e8f7247943835?editors=1111 by dadacoded (@dadacoded) on CodePen Link to comment Share on other sites More sharing options...
ZachSaucier Posted February 24, 2021 Share Posted February 24, 2021 From my understanding, it comes from the time it takes things to initialize. The globalTimeline (and exportRoot) have to keep a timeline running all the time and place animations/timelines where they need to be on that timeline. 1 Link to comment Share on other sites More sharing options...
tailbreezy Posted February 24, 2021 Author Share Posted February 24, 2021 If that is true. It seems it gets initialized the moment the gsap script is loaded. Since setting timelines after load results in the same. window.addEventListener('load', () => { var tl = gsap.timeline() .to('.box', { x: 200}) console.log(gsap.globalTimeline.duration()) // ~1.281 console.log(gsap.exportRoot().duration()) // ~1.281 console.log(tl.duration()) // 0.5 }) Link to comment Share on other sites More sharing options...
tailbreezy Posted February 24, 2021 Author Share Posted February 24, 2021 Yup. window.addEventListener("load", () => { function loadScript(src) { return new Promise(function (resolve, reject) { var s; s = document.createElement("script"); s.src = src; s.onload = resolve; s.onerror = reject; document.head.appendChild(s); }); } loadScript("https://unpkg.co/gsap@3/dist/gsap.min.js").then(() => { var tl = gsap.timeline().to(".box", { x: 200 }); console.log(gsap.globalTimeline.duration()); // 0.5 console.log(gsap.exportRoot().duration()); // 0.5 console.log(tl.duration()); // 0.5 }); }); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now