Jump to content
Search Community

Click to anchor in timeline

Dave Dublin test
Moderator Tag

Recommended Posts

Hi

Is it possible to click to a point in the timeline animation?

I tried to utilise the following code but I think I am missing something.

Should I be using Labels?

The idea is that you can click on the number and it will scroll to the card

 

gsap.utils.toArray(".nav a").forEach((a, i) => {
      a.addEventListener("click", e => {
        e.preventDefault();
        gsap.to(window, {scrollTo: i * innerWidth})
      });
    });

 

See the Pen dyeYdRK by davedublin (@davedublin) on CodePen

Link to comment
Share on other sites

You really don't need jQuery. It's a waste in this case and you're eating up a lot of resources with that scroll event handler. Here's a version that shows a different approach: 

See the Pen QWryzba?editors=0010 by GreenSock (@GreenSock) on CodePen

 

FYI, there are some helper functions in the docs related to getting scroll positions although they don't necessarily fit this case (I just wanted to let you know they are there): 

https://greensock.com/docs/v3/HelperFunctions#getScrollPosition

 

I hope that helps!

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