Jump to content
GreenSock

raana

How can ScrollTrigger run the animation from the moment the page loads?

Recommended Posts

I have an array that changes as the page scrolls in order of svg shapes, I need the first shape to be displayed on page load. Therefore, I entered the first path d manually and statically.
When I scroll to the end of the page and then go back to the beginning, it does not display the first page. Therefore, I returned the first shape to the array, but now the first shape is displayed twice in a row, and I want each one to be displayed only once.
  I read the DOC, but I didn't get anything, maybe I didn't read it correctly :(

 

           for(let i = 0 ; i < heroSlides.length ; i++){
          tl.to("#Tear",{
                delay: 0.3,
                duration: 0.5,
                attr:{d:heroSlides[i].path,}})
            .to("#rect",{attr:{style:`fill:${heroSlides[i].fill}`},
                  delay:0.75,
                  
              },"-=0.3")
            .call(changeBoxes, [i],"-=0.4");
        }   
const scroll = ScrollTrigger.create({
            trigger: ".module",
            pin: true,
            scrub: true,
            start: 'top top',
            end: "max", 
            animation: tl,
            // markers: true,
            pinReparent: true, 
            fastScrollEnd: false, 
        });
        scroll.scroll();

 

Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

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

 

If you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

  • Like 1
Link to comment
Share on other sites

On 9/2/2022 at 6:52 PM, GSAP Helper said:

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

 

 

If you're using something like React/Next/Nuxt/Gatsby or some other framework, you may find CodeSandbox easier to use. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Hi, I put my code in codesandbox but although it works in my local system, it doesn't work here at all, I hope you can help me.

https://codesandbox.io/s/busy-dewdney-u7h30r?file=/src/App.js:3706-3718

Link to comment
Share on other sites

Hey @raana,

 

Your codesandbox sample doesn't have any scroll on the main container,  so making this adjustment creates a scroll to test how ScrollTrigger is working:

<div style={{ height: "100vh" }}></div>
  <div className="index-module--container--J02ig">
    <!-- REST OF YOUR JSX -->
  </div>
<div style={{ height: "200vh" }}></div>

As for running a ScrollTrigger animation (or a part of it) when the page loads, you'll have to tinker with the start position of the ScrollTrigger instance to play part of the animation after the content is loaded.

 

Happy Tweening!!!

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