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

What is Framer? Join the Community
Return to index
Jacek Stryk
Posted Feb 01 - Read on Facebook

Is there a way to limit the scope of the animation listener events? Oftentimes I listen to "layerA.onAnimationEnd" somewhere and it does what I need it to do.

But the unintended side effect is that if I animate layerA somewhere else the event fires again.

How do I confine/limit the event listeners in general to fire once, in a specific scope, or how do I make them more "localized"?

Or maybe there is a better way of doing something ONCE upon animation end and I'm just thinking about it in the wrong way?

4 Comments

Radek Kyselý

There is actual
layerA.once Events.AnimationEnd
that fires literally "once" :D

Radek Kyselý

I'm thinking, maybe you can scope it manually. Let's say inside block where you want the event to fire, you set additional variable ›fuel = true‹ and inside the event fire the behavior only if ›fuel == true‹.

After your desired behavior ends, set fuel back false. That way, when events tries to kick in somewhere else, ›fuel‹ will be ›false‹ and behavior won't execute :)

Jacek Stryk

Hey Radek Kyselý layerA.once is a great tip! How did you find the layerA.once? I do not see it in the docs.

Anyways I figure the complete syntax is layerA.once Events.AnimationEnd, (animation, layer) ->

Also on the manual scoping I tried it and it kind of works, just need to remember to set conditions outside of the event listener based on which it fires or not. I like your layerA.once suggestion better though cause it is simpler and just works :)

Radek Kyselý

Jacek I just remember someone used it here in the group some time ago and personally use it once in a while :)
But yea, I believe it's not documented (lot of stuff isn't, actually) :)

I agree .once is much more elegant than conditionals and variables, but it might not serve all scenarios. I'm glad it works for you though :)

Read the entire post on Facebook