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

What is Framer? Join the Community
Return to index
Dan Freeman
Posted Jun 09 - Read on Facebook

I am trying to get a layer to move to the location of each child when clicked but its X value isn't changing. I also tried changing the layer.x to index.x and it didn't work.

Mike Johnson has a video in FramerCasts using this method but for a different result which helped get me this far but now I am stuck.

it may be worth noting that this is inside a scrollComponent?

What is missing?


Mike Johnson

always have to be careful when using variables in loops. In this case it would probably move highlight to the last (or first) layer in invites.children since the onclick function does not close over the layer variable.

Not the most accurate explanation, but conceptually you can think of it like this: your layer variable is getting updated each time the loop is called, and your onClick occurs some time in the future. You are accessing that same "layer" variable which by the time you click the layer has already been set to the last item in the array (or first, since children sometimes render backwards order)

In coffeescript you can use the -> to your benefit by accessing "this" instead of "layer".

layer.onClick ->
highlight.x = this.x

Mike Johnson

This article is quite good for the explanation and another option for fixing the problem.

Dan Freeman

Thanks for the quick response Mike! highlight.x = this.x did the trick. Don't know why I didn't think about that. Will take a look at the article as well.

Dan Freeman

PS anyone who sees this needs to go to if you are new to Framer. Mike Johnson does a really great job with his videos and has helped me immensely so far.

Read the entire post on Facebook