Jump to content


Scroll to a div using a class?

Moderator Tag
Go to solution Solved by PointC,

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



Is it possible to use the scrollto plugin to scroll to the top of a div based on its class or ID rather than a numeric x y position?


So something like...

.to(window, 0.8, {
    scrollTo: {
      >DIV CLASS or ID HERE<,
      autoKill: false
    ease: Power2.easeOut



See the Pen rLyajL by Ritch (@Ritch) on CodePen

Link to comment
Share on other sites

  • Solution

Hi Ritch.b  :)


You can't just drop a div ID or class in there because the animation engine needs a number, but you can easily get that number by figuring out the offset from the top.

// via jQuery

// or plain JavaScript

I've made a simple CodePen for you to see how that could work.


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


Hopefully that helps.


Happy scrolling.


  • Like 6
Link to comment
Share on other sites

That's perfect thank you.

Link to comment
Share on other sites

  • 3 weeks later...

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.