Jump to content
Search Community

scrub scroll jumps when elements pins

brogrammer01 test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hello devs, I'm working with gsap scrollTrigger on  this practice project  and i am getting this weird scroll jump when the horizontall scroll gallery section get pinned to the viewport.  This is causing unexpected behaviors in the animation and I haven't been able to figure what the problem is. Thanks for your help in advance!

See the Pen ExOGOWV?editors=0010 by Que0 (@Que0) on CodePen

Link to comment
Share on other sites

  • Solution

Hi,

 

You don't have to pin the horizontal gallery container since it outermost parent <section> is already pinned. That is basically creating the issue:

const tl = gsap.timeline({
  scrollTrigger: {
    trigger: ".gallery-wrapper",
    start: "top top",
    end: gallery_width,
    pin: true,
    pinSpacing: 1,
    scrub: 0.5,
    invalidateOnRefresh: true
  }
});

Also pinSpacing is either a boolean or a string, so in this case most likely is getting coerced into true:

!!1 // -> true

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean#boolean_coercion

 

This seems to work the way you expect:

const tl = gsap.timeline({
  scrollTrigger: {
    trigger: ".gallery-wrapper",
    start: "top top",
    end: gallery_width,
    scrub: 0.5,
    invalidateOnRefresh: true
  }
});

See the Pen ZEmVdEZ by GreenSock (@GreenSock) on CodePen

 

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

15 hours ago, Rodrigo said:

Hi,

 

You don't have to pin the horizontal gallery container since it outermost parent <section> is already pinned. That is basically creating the issue:

const tl = gsap.timeline({
  scrollTrigger: {
    trigger: ".gallery-wrapper",
    start: "top top",
    end: gallery_width,
    pin: true,
    pinSpacing: 1,
    scrub: 0.5,
    invalidateOnRefresh: true
  }
});

Also pinSpacing is either a boolean or a string, so in this case most likely is getting coerced into true:

!!1 // -> true

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean#boolean_coercion

 

This seems to work the way you expect:

const tl = gsap.timeline({
  scrollTrigger: {
    trigger: ".gallery-wrapper",
    start: "top top",
    end: gallery_width,
    scrub: 0.5,
    invalidateOnRefresh: true
  }
});

 

 

 

Hopefully this helps.

Happy Tweening!

 

 

It helps, thanks

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.
×
×
  • Create New...