Jump to content
Search Community

scrollTo Not Working as Expected

Newbie_Jim test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

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


I modified the scrollTo example code, but the result did not work as I expected.

I added offsetY to scrollTo, the first click works perfectly when the scroll position is less than the element's scroll position.
However, if I repeatedly click, the offsetY continues to apply, rather than staying fixed at the desired element and then applying the offset. When the scroll position is greater than the element's position, it cannot scroll to the desired position at all.

I expected it to work like box2. Currently, for box2, I am using a fixed y value.

See the Pen abxxyYQ?editors=1010 by sw355498 (@sw355498) on CodePen

Link to comment
Share on other sites

  • Solution

I've just written a guide how ScrollTo works. I think you don't want to scroll to an element in your case, but to the start of a specific ScrollTrigger. Check out the post below and also @GreenSock's comment. Hope it helps and happy tweening! 

 

 

  • Like 1
  • Thanks 1
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...