Jump to content
Search Community

scrollTo with expanding accordion tabs not working with scrollTrigger

mirohristov test
Moderator Tag

Recommended Posts

Hi,

I have the following project: https://old.dreamspace.co/projects/metatailor

It all works well expect when trying clicking Plans & Pricing which uses scrollTo() an offset of scrollTop( el )
I'm adding .expand class on the 5 videos which changes the total window scroll height.

As it's scrolling down the page becomes longer and the scroll never reaches the element.

 

Is there a better way to accomplish this? 

I've looked into this pen below  but it seems overly complex and not exactly what I need.

 

Thank you!

 

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

Link to comment
Share on other sites

Ah, there are several problems here...

  1. You're using CSS transitions instead of GSAP
  2. You've created logic issues with the way things are set up there because when you click on that anchor link, the browser just looks at where that target is NOW (when things are collapsed), but then on your way there, you've got things expanding out which push the entire page taller and the target element further down, so the browser has no idea how to accommodate all that. It just goes to the scroll position that it initially determined that element is sitting at. 
  3. scroll-behavior: smooth is inherently problematic for scroll-driven calculations because it completely interferes with changing the scroll position. Just like CSS transitions interfere with normal JS-driven animations because when GSAP sets a property, the browser says "NOPE! I won't do that...I'm gonna take some extra time to apply that..."

So is this possible to work around? Probably, but it's well beyond the scope of help we can provide for free here in the forums (please see the forum guidelines). We do offer paid consulting services if you need those. Just contact us privately if you'd like to explore that. 

 

Also, this won't help in this particular case because you're doing a bunch of custom logic and CSS-driven stuff, but in many cases this helper function can help: https://gsap.com/docs/v3/HelperFunctions/helpers/getScrollLookup/

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