Jump to content
Search Community

Rotating SVG elements depending on the scrolling

ainzon test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

Hi,

 

I have a question about optimizing the code I created for that animation.

 

I use the same code 3 times to achieve what you can see in codepen. I already tried to simplify that code with a timeline with no success. The problem was that only the last circle was rotating.

 

The goal was to start the rotations with an delay. So the second should start later than the first and so on - but I couldn´t achieve that. But with the fade it looks like it does.

 

I´m also not sure if my startValue and endValue - variables are so smart or if there is a better way. Is there a possibility to say that the start should be at the top of the element before and the end should be at the end of the element after?

 

Side note: I´m also not 100% happy how the circles fade in - is there a smoother way or is it just my bad timing? I should ensure that the fading is done before the user scrolls away...

 

Still learning.

 

Thanks for your help!

See the Pen wvjLpvy by boris-andraschko (@boris-andraschko) on CodePen

Link to comment
Share on other sites

  • ainzon changed the title to Rotating SVG elements depending on the scrolling
  • Solution

When working with GSAP I would always start with using a timeline. You almost never want to animate one thing and if so you can always optimize it later. Also the best thing to do with ScrollTrigger is to remove it! This seems counter intuitive, but ScrollTrigger is just animating something on scroll, so just focus on the animation at first and only when you're happy with the animation add ScrollTrigger back in.

 

I would also always gravitate to using just one ScrollTrigger, this also makes it really simple to disable it to view just the animation.

 

I've add some comments in the code to explain my reasoning, hope it helps. Also there are some great resources out there, personally I like video content. So check out these:

https://www.youtube.com/c/GreenSockLearning/videos

https://www.youtube.com/user/snorklTV/videos

 

See the Pen eYrqJXm?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen

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