Black Ducas Posted February 9, 2024 Posted February 9, 2024 10 hours ago, GSAP Helper said: Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependancies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer. Here it is The error I said is on the Codepen too: Orignal topic Quote Hi, I'm trying the quoted code. function progressBarUpdate(tween) { console.log(tween.progress()) } const tl = gsap.timeline({ delay: 1, onUpdate: progressBarUpdate, }); tl .add(animate()) .add(reveal(), 'reveal') .add(start()) The timeline itself works perfectly. I just added onUpdate: progressBarUpdate and the function, and I get this error: Quote Uncaught TypeError: Cannot read properties of undefined (reading 'progress') at Timeline.progressBarUpdate [as _onUpdate] The problem comes from this line console.log(tween.progress()) Any idea? See the Pen dyrqqPy?editors=1111 by gooogooo (@gooogooo) on CodePen.
mvaneijgen Posted February 9, 2024 Posted February 9, 2024 Hi @Black Ducas I've split your reply to its own topic, no need to bother all these people 9 years later. If you would have logged tween you would see that you don't have access to it, because you never pass it to the function that you call in onComplete If you pass the current timeline as an argument to the function, you do have access to it. Check out how functions work in Javascript https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions Hope it helps and happy tweening! See the Pen oNVPPxN?editors=0011 by mvaneijgen (@mvaneijgen) on CodePen. 1
Black Ducas Posted February 9, 2024 Author Posted February 9, 2024 Thanks @mvaneijgen I thought the Rodrigo code worked on that point, maybe something is changed from 9 years ago, my fault. I'm not understanding why the progress method doesn't update the progress bar timeline, where am I wrong? See the Pen qBvMMza by gooogooo (@gooogooo) on CodePen.
Solution mvaneijgen Posted February 9, 2024 Solution Posted February 9, 2024 Yeah probably something has changed 9 years later, no worries. It is always a good idea to log the things you get to make sure they are what you think they are. In this case you can do two things. You want to tween a timeline, so all the logic should move to the timeline. Pausing a tween and then controlling the timeline is what is tripping you up here. // With a timeline let progressBarTl = gsap.timeline({ paused: true, // Timeline gets paused }) progressBarTl.from(".progress-bar", { scaleX: 0, duration: 2, ease: "none" }); // Using a single tween const progressBarTl = gsap.from(".progress-bar", { paused: true, // Tween gets paused scaleX: 0, duration: 2, ease: "none" }); See the Pen QWoVZEP?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen. Hope it helps and happy tweening! 1
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