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

What is Framer? Join the Community
Return to index
Hugo des Gayets
Posted Jan 19 - Read on Facebook

Could someone explain me how I could apply layer.animate to all layers stored in the array instead of the last one? Thanks!


Adria Jimenez

Hello Hugo des Gayets you can use @animate instead of layer.animate as "@" will contain the appropiate layer every time the click is fired. You can see an example of what I mean here:

Ben Rodenhäuser

adding '(event,layer)' to the part of your code where you set up the event should also work, like here:

Hugo des Gayets

Thanks Adria Jimenez I'll try this!

Hugo des Gayets

Thanks Ben Rodenhäuser!

Jordan Robert Dobson

Basically by the time you click layer is equal to the last element in the loop because there aren't any more to set layer to. So you have to use "this" as in this.layer or @.layer.

This refers to the element clicked that calls that function.

Hugo des Gayets

Thanks Jordan Robert Dobson!

Marc Krenn

1. You can get rid of the allLayers.push(layer) by adding every layer to the array at their creation:

'layer = allLayers[i] = new Layer'

2. You can also git rid of the second loop (just remove line 26)! Instead of animating layer ('layer.animate') on Click, use '@.animate' or 'this.animate'.

Two examples:
... here I'm using states instead of animation, but its the same logic

... contains an in-depth description of how for-loops work in conjuncture with arrays :)

Lukas Imrich

Or you can make use of closures, which is probably the least preferable solution but it works as well:

Read the entire post on Facebook