Jump to content
GreenSock

Aimack

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

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

Thank you so much @Cassie. Feeling a little bit more confident after reading your take on this. :)

Link to comment
Share on other sites

@Cassie is there any major difference between the GSAP.utils function you used to create ARRAY and the querySelectorAll that creates a NODELIST
Thanks again.

  • Like 1
Link to comment
Share on other sites

That's the difference! Arrays are nicer to deal with sometimes

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