Jump to content
GreenSock

hellehs90

ScrollTo plugin and anchors

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

Hi guys,

So I'm trying to use the scrollToPlugin to scroll to my anchor points. It's a list of items. The first time I click it works, but then it gives me errors that it's not a valid selector.

 

  $('.toc__list-item a').click(function(e){
    e.preventDefault();
    var href = $(this).attr("href");
    TweenLite.to(window, 1, {scrollTo:{y:href, offsetY:70}});
  });

 

Also, is it possible to detect with the scrollToPlugin when you have scrolled past an element? For example when <a href="#linktoheading"> has scrolled past h2#linktoheading? Thanks. 

 

Link to comment
Share on other sites

As for why it isn't working more than once, it is very tough to know without seeing how your page is setup.

 

Please fork our demo from the docs below and add your own code

 

  1. click "run pen"
  2. click "edit on codepen"
  3. click "fork"
  4. add your own html, js, css (just enough to replicate the problem)
  5. save
  6. paste the url in your reply

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

 

We will be happy to help once we can see what isn't happening and and the specific errors.

 

 

Also, is it possible to detect with the scrollToPlugin when you have scrolled past an element?

 

Sorry, the plugin doesn't have any of that type of functionality built in.

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