mark772 Posted October 8, 2021 Share Posted October 8, 2021 I want to check if the animation is active (if it is then i want to return). I saw this https://greensock.com/docs/v3/GSAP/Timeline/isActive() but i can't make it work so. See the Pen dyzbrPy by mark772 (@mark772) on CodePen Link to comment Share on other sites More sharing options...
akapowl Posted October 8, 2021 Share Posted October 8, 2021 Hey @mark772 You could store your tweens in a variable, check if that variable exists in the first place and if it does check if the tween stored in that variable isActive(). There's probably a more elegant way, but something like this would work: See the Pen 7f5bf62b0fc7e7eccead9a059b79ba5f by akapowl (@akapowl) on CodePen 1 Link to comment Share on other sites More sharing options...
Solution OSUblake Posted October 8, 2021 Solution Share Posted October 8, 2021 11 minutes ago, akapowl said: There's probably a more elegant way, but something like this would work: You can combine your undefined and isActive check like this. if (tween1 && tween1.isActive()) { ... } Another way is to use gsap.getTweensOf(). If the length is 0, that means there are no active tweens on those targets, which will evaluate to false. Any other length value will be true, which means there are active animations. if (gsap.getTweensOf([cube.rotation, cube1.rotation]).length) { ... } 2 Link to comment Share on other sites More sharing options...
akapowl Posted October 8, 2021 Share Posted October 8, 2021 6 minutes ago, OSUblake said: You can combine your undefined and isActive check like this. I tried that before and it's throwing an error See the Pen fc60f76a874e2de6e05f33b89cd1bbbb by akapowl (@akapowl) on CodePen This will of course still be shorter than what I have in my reply above: if (typeof tween1 !== 'undefined' && tween1.isActive()) { ... } Link to comment Share on other sites More sharing options...
OSUblake Posted October 8, 2021 Share Posted October 8, 2021 You just need to have tween1 somewhere in your code. let tween1; const scene = new THREE.Scene(); const scene1 = new THREE.Scene(); ... 1 Link to comment Share on other sites More sharing options...
akapowl Posted October 8, 2021 Share Posted October 8, 2021 Yup... had that too - at least I thought so. When I tried before I wrote let tween; instead of let tween1; 🤦♂️ Link to comment Share on other sites More sharing options...
mark772 Posted October 9, 2021 Author Share Posted October 9, 2021 Thank you for the quick responses. 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