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

What is Framer? Join the Community
Return to index
Caitlin Charniga
Posted May 03 - Read on Facebook

Is there a cleaner way to do this? To have one state, and assign layers to it?

5 Comments

Giovanni Caruso

Something like this...

layers = []

for i in [0..3]
layer = new Layer
width: 200
height: 200
backgroundColor: Utils.randomColor()
y: 200 * i

layers.push layer

layer.states.add
hide:
opacity: 0

for layer, i in layers
layer.onClick ->
@.stateCycle("hide", "default")

Here the project: https://framer.cloud/SfiNv

Jonathan Lazarini

Array with a loop perhaps or a map :)

Mike Johnson

for the elements you want to share the state, group them up in sketch without anything else. Then you can loop over the groups children directly.

for child in sketch.groupName.children
child.states =
hide:
opacity: 1

Radek Kyselý

Or this, but I'd also go with grouping as Mike said.

George Kedenburg III

you can just make your own array, no need to do all this complicated stuff with grouping...

layersToHide = [sketch.$1, sketch.$2, etc]
for layer in layersToHide
..layer.states.hide =
....opacity: 1

Read the entire post on Facebook