Jump to content
Search Community

using scrollTo() with an array

kmytor test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

  • Solution

Hi,

 

The issue is that all your links have an href attribute that points to that specific tag href="#post__0", so that basically takes the window to that section immediately which prevents the ScrollTo Plugin from doing it's job. Simply prevent the default functionality on the click event and watch your app smoothly scroll to the section you want:

btn.addEventListener("click", (e) => {
  e.preventDefault(); // <- THIS
  gsap.to(window, {
    duration: 1,
    scrollTo: {
      y: "#post__" + index,
      offsetY: 70,
      ease: "power2"
    }
  });
});

Happy Tweening!

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