0

I'm building a function that's supposed to let a layer work like an on and off switch, dropping every layer that is higher than it in the array and then, when clicked again, return all the layers to their original position. I managed to make it target the right layers when turning it on, but I can't get it turn off (close back) Can someone please point me in the right direction to get this code to work. Thank you.

layers=[]
layerNames=[]
indexL=0

for i in [0...5]
 layer=layers[i]=new Layer
    y:230*i

 do (layers,i)->
     clickD=false
     layers[i].onClick ->
         for l,index in layers
            if @.index<l.index
                layers[index].animate
                    properties:
                        y:230*index+300
                clickD=true
            else if @.index<l.index and clickD!=false
                layers[index].animate
                    properties:
                        y:230*index
            else
                layers[index].animate
                    properties:
                        y:230*index

Framer link:https://framer.cloud/xcxXg/

  • Update: I have edited this and used stateCycle, which seemed to have solved the problem of layers not closing back in, but now if I click a layer above the active layer, @layer goes mental. – mooreEffort Mar 11 '17 at 11:18
  • layers=[] layerNames=[] indexL=0 for i in [0...5] layer=layers[i]=new Layer y:230*i layers[i].states.add on: y:228*i+300 off: y:228*i do (layers,i)-> clickD=false layers[i].onClick -> for l,index in layers if @.id>=l.id layers[index].states.switch("off") clickD=layers[i].states.current.name print clickD else layers[index].stateCycle("on","off") clickD=layers[i].states.current.name print clickD – mooreEffort Mar 11 '17 at 11:21

0 Answers0