Jump to content
Search Community

ScrollTrigger Animation

Akhil sanju test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

I have two slide elements. When scrolling, the issue arises after the slides are completed. There is a significant, unwanted space that requires scrolling through all the way to move on to the next section. In an attempt to resolve this issue, I tried using 'pinSpacing: false'. However, when set to 'false', the elements at the bottom overlap the slider. I couldn't figure out what went wrong!

See the Pen dywZQjB by euginesanju (@euginesanju) on CodePen

Link to comment
Share on other sites

hi @Akhil sanju,

The problem is not with the spacing but with a wrong selector you have used.

let sections = gsap.utils.toArray(".container .panel");

This collects the height of all the divs that contains the .panel class (I believe there were like 6).

Just change the '.container' to '.inner-wrapper' and you should have the correct amount of spacing.


Just a quick tip, i would nest the image and the text in the same section and don't create seperate sections for it.

  • Like 1
Link to comment
Share on other sites

  • Solution

Hi @Akhil sanju welcome to the forum!

 

Nice catch @IndM I came to the same conclusion!

 

It's always a good idea to log the values you're using to see if they are what you think they are. Indeed lots of tutorials use the fancy (sections.length - 1) code, but if I log your sections.length I get 6 and I see 3 slides, so something is wrong here. I've now set it manually to 2 (eg 3 - 1) and it works as expected. 

 

so you're let sections = gsap.utils.toArray(".container .panel"); is not correct, there are probably more .panels on the page in a container. Hope it helps and happy tweening! 

 

See the Pen PoXOXXQ?editors=0011 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 1
Link to comment
Share on other sites

7 minutes ago, Akhil sanju said:

Could you please explain to get the current index of each scroll section


@Akhil sanju Depends where you want to use it.

If you meant inside the foreach, you can do it like this:

 

sections.forEach((section, index) => {
  totalHeight += section.clientHeight;
  console.log(index);
});

 

  • Like 1
Link to comment
Share on other sites

For a progress bar I would approach it this way:

Creating a separate scrolltrigger that depends on your timeline, in your case the sections.
 

 gsap.to('progress', {
    value: 100,
    ease: 'none',
    scrollTrigger: { scrub: 0.3 }
  });


and add this or another div in your html:

<progress max="100" value="0"></progress>


See ref:

 

  • 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.
×
×
  • Create New...