Lee Probert Posted January 15 Posted January 15 Is it possible to use a `ScrollSmoother` and still pin elements like you would with a `ScrollTrigger` ... I have had to create individual `ScrollTrigger` instances for each of my section elements: sections.forEach((section, index) => { ScrollTrigger.create({ trigger: section, start: 'center center', end: `+=${PIN_DURATION}`, pin: true, pinSpacing: true, markers: false, // Set to true to see pin markers onEnter: () => { console.log(`Section ${index + 1} entered - pinned`); }, onLeave: () => { console.log(`Section ${index + 1} left - unpinned`); }, }); }); Can you not use the one `ScrollTrigger` instance that is available in the `ScrollSmoother`? See the Pen VYjmRBO by leeprobert (@leeprobert) on CodePen.
Rodrigo Posted January 15 Posted January 15 Absolutely! In fact it seems to be working as expected in your demo, isn't it? The ScrollTrigger instance inside a ScrollSmoother one is only for ScrollSmoother, nothing more. In order to create other ScrollTrigger instances just use the create method or use the configuration available in Tweens and Timelines: https://gsap.com/docs/v3/Plugins/ScrollTrigger/static.create() // Tween gsap.to(target, { // ... scrollTrigger: { // ... } }); // Timeline const tl = gsap.timeline({ scrollTrigger: { // ... } }); Hopefully this clear things up Happy Tweening!
Lee Probert Posted January 15 Author Posted January 15 So this is the most efficient way to do it? Create a ScrollTrigger for every element I want to pin?
Rodrigo Posted January 15 Posted January 15 Yeah, you can use ScrollTrigger batch also: https://gsap.com/docs/v3/Plugins/ScrollTrigger/static.batch() 99.9% of the times you'll see a performance issue using GSAP based only on code, normally performance problems stem from browser rendering and not JS execution. Are you encountering performance problems in your app or just a general question regarding best practices? Happy Tweening!
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