Jess.Park Posted February 5, 2021 Share Posted February 5, 2021 Hi. I *really* want to add pause in timeline by writing like this. gsap.timeline().addSpace("+=1") I saw an old post about this, with TimelineLite.prototype, so I tried converting to gsap 3.0 like below, but it doesn't work. // https://greensock.com/forums/topic/9856-inserting-a-pausedelaywait-into-timeline/?do=findComment&comment=41126&_backrid=69387 // TimelineLite.prototype.addSpace = function (position) { // return this.set({}, {}, position); // }; gsap.timeline.prototype.addSpace = function (position) { return this.set({}, {}, position); }; Now I want to use registerEffect, but it produces error when I deploy. (it works fine in development, weirdly) I also made codepen URL. It doesn't work in codepen as well. gsap.registerEffect({ name: "addSpace", effect: () => { return gsap.set({}, {}) }, extendTimeline: true, }) tl.addSpace("+=0.5); // DOMException: Failed to execute 'querySelectorAll' on 'Document': '+=0.5' is not a valid selector. I'm working on a project that requires a lot of adding pause between tweens, so I really want to make this work. I think the error is about not specifying targets, but I can't figure it out how to fix it. See the Pen eYBJMPV by impetusjj (@impetusjj) on CodePen Link to comment Share on other sites More sharing options...
mvaneijgen Posted February 5, 2021 Share Posted February 5, 2021 I've done this in the past by just adding a `.add(() => {}, "+=1")` with an empty function. It's not that readable, but it works. See the Pen WNorJoX by mvaneijgen (@mvaneijgen) on CodePen Link to comment Share on other sites More sharing options...
Jess.Park Posted February 5, 2021 Author Share Posted February 5, 2021 5 minutes ago, mvaneijgen said: I've done this in the past by just adding a `.add(() => {}, "+=1")` with an empty function. It's not that readable, but it works. See the Pen See the Pen WNorJoX by mvaneijgen (@mvaneijgen) on CodePen by mvaneijgen (@mvaneijgen) on CodePen yes I know that works, but I just want to know is it really impossible to make it work like 'tl.addSpace("+=1")' this way. Link to comment Share on other sites More sharing options...
mvaneijgen Posted February 5, 2021 Share Posted February 5, 2021 If i give your effect an empty array it works See the Pen yLVeEYW by mvaneijgen (@mvaneijgen) on CodePen 1 Link to comment Share on other sites More sharing options...
mikel Posted February 5, 2021 Share Posted February 5, 2021 Hey @Jess.Park, from the DOCs: important: any effect with extendTimeline:true must return a GSAP-compatible animation that could be inserted into a timeline (a Tween or Timeline instance) So an 'empty tween' would have the same effect. See the Pen YzpwjzO?editors=0010 by mikeK (@mikeK) on CodePen Happy effects ... Mikel 1 Link to comment Share on other sites More sharing options...
Jess.Park Posted February 5, 2021 Author Share Posted February 5, 2021 2 hours ago, mvaneijgen said: If i give your effect an empty array it works You're right, this works. I'm sad that I can't do it the way I wanted, (.addSpace("+=1")) but maybe I should settle for this. Link to comment Share on other sites More sharing options...
Solution GreenSock Posted February 5, 2021 Solution Share Posted February 5, 2021 Here's a pretty clean way of doing it: See the Pen wvoMZWJ?editors=0010 by GreenSock (@GreenSock) on CodePen gsap.registerEffect({ name: "addSpace", effect: targets => gsap.to(gsap.effects.addSpace, {duration: targets[0]}), extendTimeline: true }); Usage: tl.addSpace(2) // add 2-second empty tween Basically we're ignoring config, and passing the number in as the target. Just keep in mind that GSAP will always separate out targets into an Array, so we just reference it with targets[0]. Beware that we don't want to pass in a string because GSAP will interpret target strings as selector text. I'm using gsap.effects.addSpace as the target of the tween simply so that we have a clean way of GETTING all the space-related stuff in a timeline, like timeline.getTweensOf(gsap.effects.addSpace) would return all those. You'd probably never need that, but I figured it's better give you that flexibility down the road just in case. Does that help? 4 Link to comment Share on other sites More sharing options...
Jess.Park Posted February 6, 2021 Author Share Posted February 6, 2021 8 hours ago, GreenSock said: Here's a pretty clean way of doing it: gsap.registerEffect({ name: "addSpace", effect: targets => gsap.to(gsap.effects.addSpace, {duration: targets[0]}), extendTimeline: true }); Usage: tl.addSpace(2) // add 2-second empty tween Basically we're ignoring config, and passing the number in as the target. Just keep in mind that GSAP will always separate out targets into an Array, so we just reference it with targets[0]. Beware that we don't want to pass in a string because GSAP will interpret target strings as selector text. I'm using gsap.effects.addSpace as the target of the tween simply so that we have a clean way of GETTING all the space-related stuff in a timeline, like timeline.getTweensOf(gsap.effects.addSpace) would return all those. You'd probably never need that, but I figured it's better give you that flexibility down the road just in case. Does that help? OMG this is exactly, even better than I wanted! You guys in GreenSock are just amazing. Thank you so much! 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