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

What is Framer? Join the Community
Return to index
William Hutter
Posted Jul 22 - Read on Facebook

Hey guys,
Quick question :
Is there a way to say

"if layer is in this state do this
else do that"

?

Thanks !

9 Comments

Benjamin Den Boer

One way to do this would be to couple any interaction where you switch states with anything else you'd like to do. For example:

On click -> Switch to StateA and Fade Background
When switched to StateA -> Show Background

On click of other button -> Switch to StateB and Fade Background again, etc.

These events may be useful to you:
Events.StateWillSwitch
Events.StateDidSwitch
Events.AnimationEnd

William Hutter

thanks Benjamin, could you help me writing this down in Coffeescript ?

Benjamin Den Boer

Hey William, sure! This is a small example:

imageLayer.on Events.Click, ->
imageLayer.states.switch("second")

imageLayer.on Events.AnimationEnd, ->
backgroundLayer.animate
properties:
opacity:0
time:0.5

Benjamin Den Boer

So on click of the layer, we switch states and when the state has been switched [the animation played] we animate the backgroundlayer

William Hutter

very cool, thanks :)

Benjamin Den Boer

Note that everything within the functions (->) is indented with a tab :)

William Hutter

of course!

Andreas Wahlström

and here's an example of willswitch. didswitch works similarly.

imageLayer.states.on Events.StateWillSwitch, (oldState, newState) ->
if oldState is "second"
print "switching from second to third"

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

William Hutter check this CodePen for the answer: http://codepen.io/akolchenko/pen/vJdtx

Read the entire post on Facebook