Poylar Posted October 18, 2022 Share Posted October 18, 2022 hi. im trying to get direction from Smoother. let smoother = ScrollSmoother.create({ wrapper: "#smooth-wrapper", content: "#smooth-content", smooth: 1.5, effects: true, onUpdate: (self) => { /* i try also like this: self.scrolltrigger.direction smoother.scrollTrigger.direction */ }, }); /* and like this */ window.addEventListener("scroll", (e) => { let nativeScrollVelocity = smoother.scrollTrigger.direction; console.log(nativeScrollVelocity); /** that works ok, but i want get this value from onUpdate() }); if i write self.scrollTrigger.direction i got error: Quote SmoothScroll.js?t=1666106728460:17 Uncaught TypeError: Cannot read properties of undefined (reading 'direction') at onUpdate (SmoothScroll.js?t=1666106728460:17:36) at Tween2.onUpdate [as _onUpdate] (ScrollSmoother.js:630:37) at _callback2 (gsap-core.js:990:62) at Tween2.render3 [as render] (gsap-core.js:3452:9) at _lazySafeRender2 (gsap-core.js:192:13) at Tween2.totalTime (gsap-core.js:1719:7) at Tween2.totalProgress (gsap-core.js:1732:36) at self.update (ScrollTrigger.js:1545:23) at self.setPositions (ScrollTrigger.js:1665:12) at onRefresh2 (ScrollSmoother.js:674:14) but can can get only 'self'. how is possible? should i get this values from window.onScroll.listeners?Or i can get values from callback? and second quest about pos:absolute header. i put header outside #smooth-wrapper but on scroll my header still going to up on scroll. i want to header keep staying on his position. Thank you. Link to comment Share on other sites More sharing options...
Solution GreenSock Posted October 18, 2022 Solution Share Posted October 18, 2022 The property is .scrollTrigger and the onUpdate will get called once DURING instantiation of the ScrollTrigger, thus that property hasn't been set yet on the ScrollSmoother. It's just an order-of-execution thing during construction. It can't assign the scrollTrigger before it's fully instantiated. Also keep in mind that the .scrollTrigger's direction will reflect the NATIVE scroll direction, not the smoothed one. But you can easily get the smoothed one by using getVelocity(). Here's a quick demo showing both: See the Pen PoevjQj by GreenSock (@GreenSock) on CodePen 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