How to iterate through all the sublayers in Framer

3.9k views Asked by At

sorry for stupid question, i need to animate all sublayers in some particular layer. How to iterate through all the sublayers?

2

There are 2 answers

1
seoh On BEST ANSWER

You can iterate sublayers of a layer via for-in loop

for child in layer.subLayers
    child.animate
        properties: 
            x: Utils.randomNumber(100)
            y: Utils.randomNumber(100)

if you need an index of each sublayer, you can change loop like this

for child, i in layer.subLayers
0
bennewton999 On

I came across this question looking for a similar solution. I wanted to change all subLayers in a given layer, even deep nested layers. In the Docs I found descendants. Adding here in case someone is looking for a solution to iterate all nested subLayers.

for descendant in layers
    descendant.ignoreEvents