Jump to content
Search Community

Having a problem with GSAP and QuerySelector

momo12 test
Moderator Tag

Recommended Posts

@momo12 I spent a bunch of time writing a custom helper function for you in the other thread you created about this same topic - did you see that?: 

Your demo code has several problems: 

  1. You are only checking to see if each iteration through the loop is odd or even, but that has [almost] nothing to do with how those elements are actually being displayed in the grid. Y
  2. You're looping through the elements that serve as the column containers, not the boxes themselves. 
  3. You're treating columns as if they're rows
  4. You're setting a singular variable every time through the loop. So at the end, you'll just have one element rather than an Array of elements. 
  5. It looks like you're trying to treat a variable name as a string and feeding it into a tween which will be treated as selector text. In other words, gsap.set("evenColumns", ...) is like telling GSAP to animate the elements document.querySelectorAll("evenColumns") (literally <evenColumns> HTML tags)

None of this is related to GSAP - it's all plain JavaScript and logic issues. 

 

I'd strongly recommend that you just use the helper function I made for you. 

See the Pen BaVOOjv?editors=1010 by GreenSock (@GreenSock) on CodePen

  • Like 1
Link to comment
Share on other sites

Just now, GreenSock said:

"

 

1 minute ago, GreenSock said:

@momo12 I spent a bunch of time writing a custom helper function for you in the other thread you created about this same topic - did you see that?: 

Your demo code has several problems: 

  1. You are only checking to see if each iteration through the loop is odd or even, but that has [almost] nothing to do with how those elements are actually being displayed in the grid. Y
  2. You're looping through the elements that serve as the column containers, not the boxes themselves. 
  3. You're treating columns as if they're rows
  4. You're setting a singular variable every time through the loop. So at the end, you'll just have one element rather than an Array of elements. 
  5. It looks like you're trying to treat a variable name as a string and feeding it into a tween which will be treated as selector text. In other words, gsap.set("evenColumns", ...) is like telling GSAP to animate the elements document.querySelectorAll("evenColumns") (literally <evenColumns> HTML tags)

None of this is related to GSAP - it's all plain JavaScript and logic issues. 

 

I'd strongly recommend that you just use the helper function I made for you. 

 

 

Thanks for sharing this. I know. I'm just trying to learn more with different solutions to learn better GSAP. 

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