Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
elegantseagulls

ScrollTrigger Batch Kill

Recommended Posts

So I'm having trouble killing a ScrollTrigger Batch without killing all the tweens on a page. I thought I could just use the ScrollTrigger.getAll('myID').forEach(st => st.kill('all')); , but this kills all the ScrollTriggers on the page. It also seems like I can't access them with the getById method either.

Any suggestions?

See simplified example of my usecase:

See the Pen wvPvXXZ?editors=0010 by ryan_labar (@ryan_labar) on CodePen

Link to comment
Share on other sites

Ok, I found a solution (added in CodePen), but I'm hoping there's a simpler way. 

 

ScrollTrigger.getAll().forEach((st, i) => {
    // SOLUTION
    if (st.trigger.classList.contains('card')) {
      st.kill("all")
    }
  });

 

Link to comment
Share on other sites

.batch() returns an array of ScrollTriggers. Is that what you are looking for?

 

let triggers = ScrollTrigger.batch(...)

 

Also, I'm not sure what the "all" here is for.

st.kill("all")

 

It doesn't look like .kill() takes a string parameter.

https://greensock.com/docs/v3/Plugins/ScrollTrigger/kill()

 

Link to comment
Share on other sites

Yep, Blake is right. So it should be as simple as:

let triggers = ScrollTrigger.batch(...);
                                   
triggers.forEach(st => st.kill());

Does that answer your question @elegantseagulls

 

Love seeing how active you've been in the forums helping folks 🙌

  • Like 1
Link to comment
Share on other sites

7 hours ago, OSUblake said:

Also, I'm not sure what the "all" here is for.

Tween.kill() habits for kill is why "all" is in there. Good catch!

 

7 hours ago, GreenSock said:

Does that answer your question @elegantseagulls

Yes! Thank you!

 

Unfortunately, however, my batch setup isn't in same scope as where I'm killing it, so I don't have a good way to access that....

 

It'd be awesome to be able to getAllById('id') (especially for ScrollTriggers setup in a forEach loop) or getBatchById('id'), but maybe my use case isn't all that common. The way I've got it setup seems to work pretty well for what I'm doing in the meantime.

Link to comment
Share on other sites

What about something like this?: 

ScrollTrigger.getAll().forEach(st => st.vars.id === "my-id" && st.kill());

 

  • 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.
×