Jump to content
Search Community

ScrollTrigger automatically jumps when pinned section not in view (on mobile)

amit95 test
Moderator Tag

Recommended Posts

I have what looks to be a rare bug with my pinned section. When viewing a page which contains this pinned section, on mobile, it will automatically start jumping up and down.

 

Here are visual of my issue:

  • Video (notice the automatic jump 13s in)

 

In the above visual, it is automatically jumping up and down (I'm not scrolling near the end).

 

In my demo, I've stripped back all of my JS to test what may be causing this. However, the issue persisted. It only works if I comment out pin: ".horizontalScroller", which I cannot, as it's pivotal.

 

It works fine on desktop, no jumping, but when viewing on a mobile device, it starts to jump. I can only assume calculations with .pin-spacer are messing up, because once I'm passed that section,  it almost jumps up to pin again., then realises it shouldn't do that so goes back down, when the element isn't even in view. 

 

See sandbox here (again, the effect I'm having is on mobile)

 

Any ideas?

 

Link to comment
Share on other sites

Hey amit, 

 

I'm not able to reproduce the jumping you are talking about. Does the jumping happen if you remove all your animations? Pinning on mobile can be tricky due to the reasons mentioned here.

 

 

Also, is there any reason you are doing the animations manually instead of using something like the containerAnimations?

 

 

 

  • Like 1
Link to comment
Share on other sites

Hi @OSUblake

 

Yes that's correct. Even when I remove everything and have just the below, it still jumps (and that's testing after clearing cache).

 

let container = document.querySelector(".horizontalScroller__items");

gsap.to(container, {
  ease: "none",
  scrollTrigger: {
    trigger: ".horizontalScroller",
    pin: ".horizontalScroller",
    anticipatePin: 1,
    scrub: 0.2,
    invalidateOnRefresh: true,
    refreshPriority: 1,
    end: '+=450%',
  }
});

 

In regards to containerAnimation, I actually tried this approach a few weeks back, but couldn't get it to work. I then reached out for guidance on Stack Overflow and there they told me that "Pinning and snapping won't work on ScrollTriggers with a containerAnimation" (

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

)

Link to comment
Share on other sites

8 hours ago, amit95 said:

I actually tried this approach a few weeks back, but couldn't get it to work. I then reached out for guidance on Stack Overflow and there they told me that "Pinning and snapping won't work on ScrollTriggers with a containerAnimation"

 

It will work on main ScrollTrigger, just not for the child containerAnimations as that wouldn't make much sense...

 

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

 

As for the jumping, I'm still not seeing anything on Android or iOS. What device are you seeing issues on?

 

Link to comment
Share on other sites

Just to make sure I understand this jump you're talking about. I scrolled past the purple section on mobile and then it scrolls back up. Is that what you are referring to?

 

The only thing thing that I can think of right now is to try removing the anticipatePin property and maybe the refreshPriority.

 

Link to comment
Share on other sites

@OSUblake - You're correct, that's what I'm referring to.

 

I've removed anticipatePin and refreshPriority before and have done so again. After clearing cache, this issue still remains, still jumps.

 

Note: I've added both properties back in so that it doesn't effect desktop.

Link to comment
Share on other sites

1 hour ago, amit95 said:

Are you saying the CSS is part of the issue (if so, are you saying to remove it)?

 

Yes, the smooth scroll behavior can mess with it. As for the preventing resize, you would have to use a fixed scroller. The only downside is the address bar will always be visible.

 

https://greensock.com/docs/v3/HelperFunctions#scrollResize

 

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