Jump to content
Search Community

ScrollToPlugin position issues

ad_bel test
Moderator Tag

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

See demo link and click on any of the links to see issue:
 

 

Basically I am using ScrollMagic and overriding the scrollTo with:

 

        const scrollTween = (target) => {
          
            TweenMax.to($('.base'), 0.7, {
                scrollTo: {
                    y: target
                },
                ease: Power1.easeInOut
            });
        };
 
        controller.scrollTo(scrollTween);
 
        //  Bind scroll to anchor links
        $(document).on("click", "a[href^=#]", function(e) {
 
            let id = $(this).attr("href");
 
            if ($(id).length > 0) {
 
                e.preventDefault();
              
                // trigger scroll
                controller.scrollTo(id);
 
                // if supported by the browser we can even update the URL.
                if (window.history && window.history.pushState) {
                    history.pushState("", document.title, id);
                }
            }
        });
 
 
Note: I am trying to animate a container instead of window because I need momentum scrolling in IOS so i set overflow: hidden on html/body, and overflow-y: scroll and overflow-scrolling: touch on container. This was the only way it would somewhat work. Maybe my approach is wrong?
 
css snippet (see full in link provided):
 
html, body {
    padding: 0;
    margin: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
}
 
#app {
    height: 100%;
    width: 100%;
}
 
.base {
    height: 100%;
    width: 100%;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
}

 

If you try the links the behave erratically. For example when you click on the first two they seem to work, third not all, 4th animates but to the wrong position. When you click the same link it animates up and down!

 

I created an issue in the ScrollMagic repo as well but I think it has to do with the ScrollToPlugin and how my css is structured. I have tried every css variation I can think and still can't get this to work.

 

Any help would be appreciated!

 

 

See the Pen by N1uIxlW8f (@N1uIxlW8f) on CodePen

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums,

 

I really know very little about ScrollMagic.

It seems you are passing a tween into ScrollMagic's controller.scrollTo() method

 controller.scrollTo(scrollTween);

But according to the ScrollMagic docs that doesn't seem like a valid parameter type:

 

http://scrollmagic.io/docs/ScrollMagic.Controller.html#scrollTo

 

I think you may want to pass in a function that creates the tween for you.

  • Like 1
Link to comment
Share on other sites

Hi ad_bel :)

 

Welcome to the GreenSock forums.

 

One of our moderators (Petr Tichy) has loads of tutorials and info about ScrollMagic. Please take a look at this demo as it's almost the same thing you're creating:

 

https://ihatetomatoes.net/a-simple-parallax-template-using-scrollmagic-and-greensock/

 

Hopefully that helps a bit.

 

Happy scrolling.

:)

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