Author Share Posted September 17, 2021 Hey @GreenSock, thank you for your tip! The option with the timeline sounds easy, do you have a resource about how to place callbacks on a timeline or something similar? Thanks! Link to comment Share on other sites More sharing options...
Share Posted September 17, 2021 48 minutes ago, lumuxd said: Hey @GreenSock, thank you for your tip! The option with the timeline sounds easy, do you have a resource about how to place callbacks on a timeline or something similar? Thanks! You can add callbacks on your timeline like this: const tl = gsap.timeline({ onUpdate:..., onComplete:..., onStart:..., ... }); Or you can use eventCallback() or call() , depending on what you need. 3 Link to comment Share on other sites More sharing options...
Share Posted September 17, 2021 8 hours ago, lumuxd said: The option with the timeline sounds easy, do you have a resource about how to place callbacks on a timeline or something similar? Yeah, I was thinking about .add() of a function in a timeline: let tl = gsap.timeline(); tl.add(() => console.log("1"), 1) // insert at exactly 1 second into the timeline .add(() => console.log("2"), 2) // exactly 2 seconds into the timeline //...etc. Of course you'd likely have other tweens in the timeline too (although that's not necessary). I'm just trying to focus on the .add() stuff here. You can use .call() too if you need to pass parameters. Link to comment Share on other sites More sharing options...
Author Share Posted September 20, 2021 @nico fonseca, @GreenSock thanks to both of you, I'll try this in the upcoming days! 2 Link to comment Share on other sites More sharing options...
Author Share Posted October 6, 2021 Hey @GreenSock, thanks again for your last tip. But If I get this right, your code is adding a different function each second - is that correct? In this case I am not looking for a time-based solution, but for something which is triggered as soon as a specific element is being snapped / in center of the viewport.. Do you maybe have a similar solution for me, but not time-based? Thanks! Link to comment Share on other sites More sharing options...
Share Posted October 6, 2021 What was wrong with using the onComplete callback? It shouldn't be too hard to figure out the index of the element that is snapped. Some pseudo code. snap: { snapTo: 1 / 33, duration: 0.5, onComplete: (scrollTrigger )=> { let index = Math.round(scrollTrigger.progress * 33); let currentElement = arrayOfMyElements[index]; } }, 4 Link to comment Share on other sites More sharing options...
Author Share Posted October 14, 2021 Hey @OSUblake sorry for getting back so late, thanks you for you code, this would work perfectly for me. 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