Black Ducas Posted October 12, 2021 Share Posted October 12, 2021 Hi, I'm creating a ScrollTrigger for each cards on my page. I need to do things after the ScrollTrigger has ended to initialize. I can't find a callback (like onComplete) to do this. Any help? cards.forEach(card => { ScrollTrigger.create({ scrollTrigger: { trigger: card.querySelector(".title"), // onEnter: (self) => { ... } // I need something like this: onComplete: function() { console.log("ScrollTrigger initialized"); // Doing things } }, }) }) Link to comment Share on other sites More sharing options...
OSUblake Posted October 12, 2021 Share Posted October 12, 2021 Are you looking for the onLeave callback? Quote onLeave Function - A callback for when the scroll position moves forward past the "end" (typically when the trigger is scrolled out of view). Link to comment Share on other sites More sharing options...
Black Ducas Posted October 12, 2021 Author Share Posted October 12, 2021 @OSUblake Hi, no I need a callback that is called after ScrollTrigger.create() is initialized. This is not related to user scrolling or scroll positions. What I'm doing now is using a seTimeout but it's awful and risky setTimeout(function() { // Doing things *after* ScrollTrigger.create() is initialized, considering that it finished in 1 second. This is obviously dirty and not precise }, 1000); Link to comment Share on other sites More sharing options...
OSUblake Posted October 12, 2021 Share Posted October 12, 2021 You listen for some of ScrollTrigger's events...https://greensock.com/docs/v3/Plugins/ScrollTrigger/static.addEventListener() Link to comment Share on other sites More sharing options...
OSUblake Posted October 12, 2021 Share Posted October 12, 2021 So if you only want it to run once, you could something like this. ScrollTrigger.addEventListener("refresh", myCallback); function myCallback() { ScrollTrigger.removeEventListener("refresh", myCallback); ... } Link to comment Share on other sites More sharing options...
GreenSock Posted October 12, 2021 Share Posted October 12, 2021 1 hour ago, Black Ducas said: @OSUblake Hi, no I need a callback that is called after ScrollTrigger.create() is initialized. This is not related to user scrolling or scroll positions. What do you mean by "initialized"? Initialization happens immediately in .create(), so I'm a bit confused. Perhaps you mean "when the start and end values are finished populating"? That happens on "refresh" events, as Blake pointed out. So yes, you could just listen for that. 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