Aimack Posted January 22, 2023 Share Posted January 22, 2023 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 More sharing options...
Cassie Posted January 22, 2023 Share Posted January 22, 2023 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 2 Link to comment Share on other sites More sharing options...
Solution Cassie Posted January 22, 2023 Solution Share Posted January 22, 2023 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 2 Link to comment Share on other sites More sharing options...
Aimack Posted January 23, 2023 Author Share Posted January 23, 2023 Thank you so much @Cassie. Feeling a little bit more confident after reading your take on this. Link to comment Share on other sites More sharing options...
Aimack Posted January 23, 2023 Author Share Posted January 23, 2023 @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. 1 Link to comment Share on other sites More sharing options...
Cassie Posted January 23, 2023 Share Posted January 23, 2023 That's the difference! Arrays are nicer to deal with sometimes 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now