Jump to content
Search Community

Not getting how to calculate exact snap position.

Bhavin
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Posted

 
hey this is my codepen and i am not getting snap to positions i am adding resizing and requestanimationframe logic to tackle browser hiding and showing addressbar in mobile devices (because with normalizescroll its not perfect is IOS).

and because i am resizing my divs in scroll-container thats why i am counting end position by offestHeight and scrolltrigger.refresh on resize. (but i am not getting about snap to positions)

See the Pen GgKXWXr by Bhavin-Raut (@Bhavin-Raut) on CodePen.

  • Solution
Posted

Hi,

 

Maybe something like this:

See the Pen ogvPebR by GreenSock (@GreenSock) on CodePen.

 

Also your codepen was loading two different versions of GSAP (not really a good idea) and both very old ones. Your version of ScrollTrigger was also quite old. Get the habit of always using the latest ones.

 

Hopefully this helps

Happy Tweening!

Posted

Thanks @Rodrigo its nice but still it won't work because when my address hides or shows my section height will resize and due to it my layout will shift upward or downward so my next section thinks i scroll and then my next section will pin to 0. 

Posted

@Rodrigo IgnoremMobileResize ignore only for automatic resize refresh. But i am doing manual refresh also by code after changing my section height on resize.

Posted

If you're changing the height of the elements then you have to refresh the ScrollTrigger instances, I see no other way around it. After the refresh is complete ScrollTrigger will update the instances depending on the scroll position and if you want to snap at the start/end of each section that is exactly where it will go based on the scroll position and the height of the elements and the viewport height as well.

 

Another option could be the clearScrollMemory method:

https://gsap.com/docs/v3/Plugins/ScrollTrigger/static.clearScrollMemory()

 

If this is not working, create a demo that clearly illustrates the issue and describe the way to reproduce the problem. Also present a debug URL for the codepen demo so we can test directly on real devices and not our desktop browsers.

  • Like 1
Posted

Thank yo so much @Rodrigo still i didn't tested on all devices but its working fine. if there is problem i will debug it and upload debug url to feed once again thank you for help.

  • Like 1

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