aijololo Posted May 15, 2021 Share Posted May 15, 2021 Hello! I am having a problem with running a function inside a timeline with onComplete. Instead of running when the tween is complete, the function runs when page loads. Am I missing something obvious here? Created a codepen with a simplified example. Thanks! See the Pen QWpENqO by joel-udd (@joel-udd) on CodePen Link to comment Share on other sites More sharing options...
Solution Rodrigo Posted May 15, 2021 Solution Share Posted May 15, 2021 Hi and welcome to the GreenSock forums. The issue is that right now you're executing the function, so as soon as the browser gets to that part of the code the playSound function is executed. GSAP has an excellent callback system that allows you to pass parameters, set scope, etc. This should work as expected: tl.to("#knapp", { background: "#a6a6a6", onComplete: playSound, onCompleteParams: ["knapp0"] }); Here you can learn more about callbacks, just scroll down to the Special Properties section: https://greensock.com/docs/v3/GSAP/gsap.to() Happy Tweening!!! 4 Link to comment Share on other sites More sharing options...
aijololo Posted May 16, 2021 Author Share Posted May 16, 2021 That worked perfectly! Thank you so much for the quick response! 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