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

What is Framer? Join the Community
Return to index
Olly Reeve
Posted Mar 11 - Read on Facebook

Hi, I'm trying to create an array and add a hover state. My code at the moment is adding the hover state but applies it to the last item in the array. I'm guessing that it's something to do with the layers having the same name..? If anyone has the answer it'd be much appreciated!


Jonas Treub

Inside the mouseover function you can replace "item" with "@" which is short for "this". The "this" keyword points at the layer with the mouseover function applied.

Each time you create an item layer the previous one is overridden. That's why only the last one changes with the current code.

Jonas Treub

item.on Events.MouseOver, (event, layer) ->
@style =
"color": "#2493df"

Ohn Ho

Your current code could work too, if you tried a forEach loop. Then you won't have to specify the range which gets pulled from the array you made. Additionally, you can specify style and html when you create each item:

range.forEach (item, i) ->
item = new Layer
x: i * 80
html: range[i]
backgroundColor: ""
"font-family": "Helvetica Neue"

Ohn Ho

Read the entire post on Facebook