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

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

I’m animating a set of layers in an array and I want to do something when all the layers have finished animating. What’s the best way of doing this?

4 Comments

Aalok Trivedi

Say you had 5 layers in the array. couldn't you do array[4].onAnimationEnd -> ?

Sigurd Tapio Mannsåker

In addition to Aalok Trivedi's suggestion, if you can't be sure that the last layer in the array will finish last, you can just set a counter that gets 1 deducted on every layer's onAnimationEnd. And every time you deduct 1 you also check if the counter is now 0. If it is, do stuff :)

Radek Kyselý

One possible solution is proposed by Aalok
›array[array.length-1]‹ gives you the last array item dynamically (without hardcoding the number).

Second possible one is to calculate collective duration of all animations and then delay certain behavior:

delayLength = array.length*duration
Utils.delay delayLength, ->

Another one: if you are generating your layers in a for loop, let's say:
you create a layer called ›menuItem‹ and then add to array, you can use menuItem.onAnimationEnd inside for loop as it will target the last item created in a loop :)

etc... I guess there's no "best way"

Giles Perry

Thanks for all of the replies. Really helpful!

Read the entire post on Facebook