Jump to content
Search Community

ScrollTo not scrolling to anchor properly

Jchrist test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

This is a fork of the one from the docs https://greensock.com/docs/Plugins/ScrollToPlugin

 

The problem: 

When scrollingTo an anchor the last one is not scrolled into proper position.

This seems to be related to the screen size / content "height" of the page 

 

This image is the original pen after opening it on my screen (1600x900) - here everything is fine

 

image.thumb.png.12a3721f130ab1e8a2aaf563aabaa7a3.png

 

But once you change the size of the code section a bit, clicking the "section 3" button does not scroll to the proper position, leaving a small part of the text over the actual anchor. 

 

image.thumb.png.ebb1e5b1c047ea4a2f5b210deebd714a.png

 

Is there a way to force scrollTop to go directly to the anchor?

See the Pen QBXYoJ by anon (@anon) on CodePen

Link to comment
Share on other sites

Hi @Jchrist

 

Welcome to the forum.

 

The plugin is working correctly. There just isn't enough window real estate after section three to scroll the window that far at certain heights/widths. You can't manually do it nor can the plugin.  You'd want to place some elements after it or set a specific size. Here's a fork where I've just set an arbitrary size for the body. You'll see that it work correctly at any window size.

 

See the Pen LBKaVW by PointC (@PointC) on CodePen

 

Hopefully that helps. Happy tweening.

:)

 

  • Like 3
Link to comment
Share on other sites

Hello Craig,

 

Thanks for pointing that out, I almost agree to that and TBH that was my initial guess - not enough content.

 

Although if you look closely at the image I pasted you might notice that there is still some space left on the scroll.

 

image.png.a836b8331a48a371460a6e3e015440ff.png

 

If you scroll down with the mouse you will also notice that the "Section 3" is under the navbar.  So it seems to be sth different.

 

image.thumb.png.118fa576423e3f4695354b49932440f7.png

 

The obvious workaround was adding an empty spacer div after the content (with hardcoded height) - the same solution you proposed.

This is a matter of trial and error to get the window size correct but it seems to happen when there is only a little of "content" overhead.

Looks like some hidden offset kicking in.

 

Anyway thanks for taking your time to respond.

J.

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