Jump to content
Search Community

Delay animation until the section is in the viewport

grantsmith test
Moderator Tag

Go to solution Solved by akapowl,

Recommended Posts

Hello,

 

This is my first attempt at a gsap project, and I seem to have got by with some research, copy and pasting and playing. I have some counters which work, albeit probably not in the most efficient manor. What I am stuck on is delaying the animation until the counters are scrolled into the viewport.

 

Would appreciate some pointers.

 

 

See the Pen MWmGBWP by grantsmith (@grantsmith) on CodePen

Link to comment
Share on other sites

  • Solution
2 hours ago, grantsmith said:

Hmm, there must be something I'm missing?

 

There are actually three major things, I noticed:

 

1) ScrollTrigger was introduced in GSAP 3.3.0 and you are making use of GSAP 3.2.2 in your codepen demo. Check the ScrollTrigger docs, right below the headline.

 

2) Since you actually want to select all elements with a class of counters, you are missing the . in front of your counters when selecting

 

// not good
const numbers = document.querySelectorAll('counters');

// better
const numbers = document.querySelectorAll('.counters');

 

and 3) when adding scrollTrigger as an object to a timeline or tween, it is supposed to be scrollTrigger in camelCase instead of ScrollTrigger

 

Changing those should already get you running better than before :) 

 

 

Edit: also you might not want to call tl.play(); at the very end of your code.

 

  • Like 1
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...