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

What is Framer? Join the Community
Return to index
Metin Saray
Posted Dec 30 - Read on Facebook

Hello,

Need a tip on functions, in coffeescript.

I have card1, card2, card3, card4 and card5, with icons1-5 as well.

They all come the say way, and go the same way. But each time i animate them manually, it makes a very long code.

What i want is, create an animation function for them for all. For example
card1.go();
card2.come();

I know states.add does this, but for sequential objects, i add their states in a "for" loop, but out of the for loop, i can't call their states anymore.

I don't know how you guys are doing these functions, but i'd like to hear.
(in coffeescript if possible)
(also dynamic functions are appreciated, e.g: function Come(int speedX, int curve) kind of logic)

Thanks in advance,
M.

5 Comments

Ed Chao

one way you can do this is create a card class extending the Layer class, and add these two methods for come and go. When you instantiate your cards they will now have methods come and go.

Jon Gold

What Ed said. On my phone at my parents' house, won't be able to get you an example until tomorrow but check out coffeescript classes and let us know if you get stuck :)

Benjamin Den Boer

Hey Metin Saray, here is a way to create a function with adjustable parameters. This also works with states. :)

Jon Gold

yo, back by my Mac. this is the kinda thing I've been doing. little bit more complicated, but when you're building bigger prototypes it keeps things clean & reusable.

Metin Saray

Thanks all of you, great examples. Jon Gold Didnt know we could OOP in Framer (:. Benjamin Den Boer This also seems really quick, ill give it a try asap

Read the entire post on Facebook