Jump to content
Search Community

Recommended Posts

Lee Probert
Posted

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.

Posted

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

So this is the most efficient way to do it? Create a ScrollTrigger for every element I want to pin?

Posted

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!

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