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

What is Framer? Join the Community
Return to index
Alex Maximets
Posted Mar 14 - Read on Facebook

Hi everyone, I'm building a function that's supposed to let a layer work like an on and off switch, dropping every layer that is higher in the array and then, when clicked again, return all the layers to their original position. I managed to make it target the right layers when turning it on, but I can't get it turn off (close back)

What am I doing wrong?
Please and Thank you.

7 Comments

Alex Maximets

Update: it's now closing back (using stateCycle) but when "l" is open if you click a previous layer, the "l" goes haywire. Koen Bok, Jonas Treub you've helped me before and I would appreciate another push in the right direction please.

Steve Ruiz

Here's a solution. Check the comments for explanations, but in short you just need to do a better check on whether *any* layer was is in its 'on' state, before deciding which layers to move. https://framer.cloud/nAgXx/

Alex Maximets

Thank you so much for your help Steve, I had no clue you could write so many functions within functions, this definitely makes things easier for me. I've updated my original file with your help (https://framer.cloud/nIvdy) to show exactly the effect I'm after, but it's a bit broken. It's meant to do the following: If you click on clayers[i] then a gap opens between clayers[i] and clayers[i+1] and "show" layer is visible, then if you press any other "clayer" this gap collapses and another one opens up between the new "clayers[i]" pressed and its clayers[i+1] and "show" layer remains visible and only if you press the current clayers[i] again then the gap between clayers[i] and clayers[i+1] closes and "show" layer is hidden

Steve Ruiz

Ah, ok. I've updated the project with the solution. This will now check whether there are any open layers, close them if there are, and wait until they're closed before opening the new layer. https://framer.cloud/nAgXx/

Alex Maximets

Thank you so much Steve. You are a life saver!

Alex Maximets

Hey Steve I was wondering, do you reckon the logic for that functionality could combine the use of that "anyOn" function? Right now this does exactly what i want, but I think it can be improved a little if the "show" layer doesn't have to animate back and forth when a layers[i] is pressed when layers{ not i} is active. What do you think?

Steve Ruiz

Yeah, if I get you, you're saying that certain layers are currently animating up and then back to where they just were, right? I'm sure there's an easy way to combine those steps for layers that will be turned on again, so that only the layers that need to move do so.

Read the entire post on Facebook