Jump to content
Search Community

registerEffect with empty target?

Jess.Park test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

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

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

  • Solution

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? 

  • Like 4
Link to comment
Share on other sites

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!

 

 

 

 

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...