This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Nadine Han
Posted Jul 03 - Read on Facebook

Hey, there got a little problem. I'm really not that into JavaScript. Wanted to write a if/else conditional. I want to say if layerxy has statexy than make something else do something else. My problem I don't know how to write it exactly.
Example what I wrote
if sketch["Button"].states == open
sketch["Button02"].visible = true

6 Comments

Алексей Кольченко

Check layer.states.current to get the name of the current state. Please watch the example: http://codepen.io/akolchenko/pen/qJnvH?editors=001

So for your example try:
if sketch["Button"].states.current == "open" ...

Nadine Han

Thank's for your help, but I didn't understand anything of the codepen example :D
Got it to work like this "if sketch02["Button"].states.current == "open"
i think this is what you meant ? ^^

Алексей Кольченко

True )

Gavin McFarland

Hey Nadine, so I think the first thing you need to do is think about when you want Framer to look for this condition as it will not look at the condition again unless it is told to listen for an event like a click.

For example:

layer1.on Events.Click, ->
....if layer1.states.current == "third"
........layer2.states.switch "second"

or see gist

https://gist.github.com/sevenupcan/f2b2c8c5928fc66dcf39

Gavin McFarland

I've added a Javascript version but I'm not sure if the syntax is right. Perhaps someone can check it for me.

Nadine Han

Thanks Gavin McFarland, that's exactly how I did it, and works just fine :)

Read the entire post on Facebook