Share Posted July 4, 2019 Hey, I just have a question regarding behaviour of stagger methods callback onCompleteAll. onCompleteAll does not fire whenever there are no DOM elements found by a tween - in other words, when there's no target DOM to tween (eg. ".nav-item" does not exist), onCompleteAll does not fire. I wish it would, since I have chain logic in my app. I also do not want to validate whether target elements exist every tween call. I simply resolve a promise on the callback and since stagger does not complete, promise does not resolve. How to deal with that? Thanks See the Pen ydqOZa by FilipWiniarski (@FilipWiniarski) on CodePen Link to comment Share on other sites More sharing options...
Share Posted July 4, 2019 Hey Filip, Could you create a minimal example of your setup so we can see exactly what's going on? It would help us decide whether or not you can do what you're wanting in another way. Link to comment Share on other sites More sharing options...
Author Share Posted July 4, 2019 8 minutes ago, ZachSaucier said: Hey Filip, Could you create a minimal example of your setup so we can see exactly what's going on? It would help us decide whether or not you can do what you're wanting in another way. Updated above Link to comment Share on other sites More sharing options...
Share Posted July 4, 2019 Thanks. I understand what you're saying, but I'm trying to understand more about the context. Right now I don't really see too much of a point. But to work around this, you could use a helper function. If the element is not found, TweenMax will return an empty array. If elements are found, the array will have a length other than 0. Knowing that, you can do something like this (FYI I changed the alert to a console.log): See the Pen BgPdzd?editors=0010 by GreenSock (@GreenSock) on CodePen 1 Link to comment Share on other sites More sharing options...
Share Posted July 4, 2019 I'm a little confused by this too, but I'd probably just put it on a little timeline like this: var tl = new TimelineMax(); tl.staggerTo(".unexisting-class", 1, {color:"red"}, 1); tl.add(functionYouNeedToFire); As Zach mentioned, the stagger method returns an array of TweenMax instances. If there are no elements, the array will be empty. By placing this on a timeline, the stagger will play normally if the element is present and then fire the add(). If the element isn't there, the .add() will fire immediately. Just my two cents. Happy tweening. 3 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