Jump to content
Search Community

Scroll to the child element in horizontal scroll

Denny test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

  • Solution

Hi @Denny and welcome to the GSAP forums!

 

The problem here is that the getScrollLookup is looking for elements with the class .section and the element with the specific ID doesn't have a class section:

let getPosition = getScrollLookup(".section", {start: "center center", containerAnimation: scrollHorizontalTween});
<div class="section" >
  Section 2
  <div id="section2">Test</div>
</div>

See where this goes wrong?

 

I made some changes in your demo, by adding a data attribute to the element that is pointing to a child and to the function returned by the getScrollLookup method in order to accommodate this particular scenario. Be aware that the element with the id has to be a direct child of the section, otherwise it won't work:

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

 

Hopefully this helps.

Happy Tweening!

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