Jump to content
Search Community

if/else statement

AKA\'77 test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I need help creating a if/else function.

 

'when you click the red square 

    if

blue square is at position x (could be any random position on the x axis)

 

green square tweens to the right'

   else if 

green square is a position x

   else

both square tweens to the right

 

& vice versa

 

See the Pen anogd by AKA77 (@AKA77) on CodePen

Link to comment
Share on other sites

hmm, this really has little to do with GreenSock, and typically questions like this are better suited for stackoverflow or other general javascript forums but I whipped up a very basic example:

 

http://codepen.io/GreenSock/pen/dff9e94b4880a59cd72840305e665a9e/

 

I wasn't sure about:

- if the value set for position x for the blue square was supposed to be the same value for position x of the green square

 

- when you say "both squares" tween to the right, I wasn't sure which 2 of the 3 squares you were referring.. I guesed blue and green.

 

- what you mean by vice versa (in this context)

 

Hope this gets you on your way. Happy Tweening!

  • Like 2
Link to comment
Share on other sites

hmm, this really has little to do with GreenSock, and typically questions like this are better suited for stackoverflow or other general javascript forums but I whipped up a very basic example:

 

See the Pen dff9e94b4880a59cd72840305e665a9e by GreenSock (@GreenSock) on CodePen

 

I wasn't sure about:

- if the value set for position x for the blue square was supposed to be the same value for position x of the green square

 

- when you say "both squares" tween to the right, I wasn't sure which 2 of the 3 squares you were referring.. I guesed blue and green.

 

- what you mean by vice versa (in this context)

 

Hope this gets you on your way. Happy Tweening!

Thanks so much using the ".left" tag does not work but "x" & "y" works fine, could you please adjust there code so it has "x" axis's instead of "left" please

Link to comment
Share on other sites

I don't know what you mean by "x doesn't work" as the demo I provided seems to work fine.

 

Regardless I made some small edits to use x instead of left.

 

http://codepen.io/GreenSock/pen/6c811c3251c9bac454ec3c33e2d40cc2?editors=001

 

x is fundamentally different than left, as x is short-hand for transform:translateX().

If you aren't familiar with css transforms read:

 

http://css-tricks.com/almanac/properties/t/transform/

http://ie.microsoft.com/testdrive/graphics/hands-on-css3/hands-on_2d-transforms.htm

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