Jump to content
GreenSock

Hector18

Update ScrollTrigger END value on resize

Recommended Posts

Hi,

 

I have this function:

 

$('.stagger-caption').each(function(){
                        var $this = $(this);                
                        var $totalHeight = $this.closest('.stagger-slide').outerHeight(true) - $this.outerHeight(true);
                              
                        const ST= ScrollTrigger.create({
                            trigger: $this,
                            start: "top top",
                            end: "+=" + $totalHeight,
                            pin: $this,
                            scrub: true,
                            invalidateOnRefresh: true                            
                        });                                               
 });

 

How can I update the END value on resize?

 

Thank you!

 

 

 

Link to comment
Share on other sites

Hi there! So the start and end values get recalculated automatically on resize, but your variable doesn't.

You can fix this by popping your calculation into a functional value, then when your scrollTrigger refreshes it will run that code again.
 

ScrollTrigger.create({
	trigger: $this,
	start: "top top",
	end: () => `+=${$this.closest('.stagger-slide').outerHeight(true) - $this.outerHeight(true)}`,
	pin: $this,
	scrub: true,
	invalidateOnRefresh: true                            
});                                               

 

Hope this helps!

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