Jump to content
Search Community

I am rewriting blocks of code in GSAP which seems like a bad practice.

Aimack test
Moderator Tag

Go to solution Solved by Cassie,

Recommended Posts

I am a beginner using GSAP and JS, so would appreciate some guidance. I believe that rewriting blocks of code is generally regarded as a bad practice. Can you please go through the text animation and image animation that I've wrote and tell me how I can optimize this?

Also, if you have any solution to the scrolltrigger positioning rather than hardcoding a % in as the start and end, let me know.

I appreciate your help, thank you.

 

Here is the codesandbox url.
LINK: https://codesandbox.io/s/kind-tdd-7q8f5v?file=/index.html

 

Link to comment
Share on other sites

Nothing wrong with that at all! 

Honestly I'd prefer readable repetitive code over 'clever' DRY code any day.

I can't find the source but this came to mind - 

 

Quote

Junior dev: My code looks like it's from a beginner JS book
Midweight dev: I know lots of clever things so it's important my code is clever so people know how clever I am
Senior dev: My code looks like it's from a beginner JS book

 

  • Like 2
Link to comment
Share on other sites

  • Solution

That being said - You could use a loop and a stagger.

But honestly, readability is so much better to aim for than DRY or any other 'best practice'.  Write whatever makes sense and is readable to you. As you learn you can gradually abstract stuff away and tidy things up. But premature optimisation is a speedy route to headaches and confusion!

https://codesandbox.io/s/infallible-voice-ccobfd?file=/script.js

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