Jump to content
Search Community

from CSS top/left to GSAP: bouncing shape around

archimedo test
Moderator Tag

Recommended Posts

Hi everyone, I made a simple animation where 3 shapes bounce around the screen (my inspiration was the dvd logo effect). I'd like to use this animation as a background for a website homepage's section.

 

The thing is that I'm afraid it is too heavy and browser resources consuming, so I was thinking to make the same thing but GSAP. Do you think that would be effective? is there a way to actually increase the performance of my animtion? can you help me understand how to achieve it with GSAP?

 

Thank you!

See the Pen zYKjJVO by archemede (@archemede) on CodePen

Link to comment
Share on other sites

Hey archimedo.

 

Using GSAP won't magically make non-performant properties become performant :) The biggest performance hit that you'll have will come from the mix-blend-mode regardless of whether or not your JS uses GSAP. The second worst thing is you're animating of the top and left properties - you should not do that but instead animate transforms (in GSAP that's the x and y properties). You're wise to use images that have the blur baked in instead of trying to do the blur in real time. Another thing to improve performance is to store the dimensions instead of calling clientWidth and clientHeight every tick because those force reflow/layout. You should instead have a resize function that updates these (and the other relevant values) when the page is resized, perhaps throttling that so it doesn't need to fire every single time the resize event fires.

 

Past that you could rewrite your code to be easier to maintain and perhaps slightly more performant but you likely wouldn't notice much of a difference performance wise.

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