Image for post
Image for post

Framer.js tips

Extending Framer to make prototyping faster and more fun

Cemre Güngör
Sep 26, 2013 · 3 min read

Update: I ended up turning all these tips into a library you can instantly include in your projects. Check out Shortcuts for Framer!

My favorite part about the Framer.js prototyping framework is being able to easily extend and tweak it to fit my workflow. In the couple weeks I’ve been using Framer, I’ve ended up writing some code that I reuse, which I wanted to share.

Make views global variables for easy access

for (var layerGroupName in PSD) {
window[layerGroupName] = PSD[layerGroupName];
}

If you run this in the beginning of app.js, you’ll be able to access each group with a simple variable name. This gets handy in a long file.

Before: PSD["View1"].animate ...
After: View1.animate ...

NB: Javascript has special rules about variable names (there are protected names and they can’t start with numbers), so pay attention to those while naming your layers.

Store original position

for (var layerGroupName in PSD) {
PSD[layerGroupName].originalFrame = window[layerGroupName].frame;
}

This way I can do

layer.x = 200;
// later…
layer.x = layer.originalFrame.x;

Even better, put the transitioned state as an attribute of the View too, so you can reuse it around your code.

layer.finalFrame = layer.originalFrame;
layer.finalFrame.x = 200;

layer.x = layer.finalFrame.x;
layer.x = layer.originalFrame.x;

Shorter default animation syntax

View.prototype.animateDefault = function(props) {
this.animate({ time: 200, curve: 'spring(400,30,200)', properties: props });
}

This way, each time I animate, I can write much shorter code:

 // Before
Posts.animate({
time: 200,
curve: 'spring(400,30,200)',
properties: {
opacity: 0,
x: 100
}
})
// After
Posts.animateDefault({ opacity: 0, x: 100 })

Reusable animation functions

// Before
Heart1.on("click", function() {
Heart.animateDefault({x: 100})
Skip.animateDefault({scale: 0.1})
Container.animateDefault({opacity: 0})
});
Heart2.on("click", function() {
Heart.animateDefault({x: 100})
Skip.animateDefault({scale: 0.1})
Container.animateDefault({opacity: 0})
});
// After
animateHeart = function() {
Heart.animateDefault({x: 100})
Skip.animateDefault({scale: 0.1})
Container.animateDefault({opacity: 0})
}
Heart1.on("click", animateHeart);
Heart2.on("click", animateHeart);

Collect your common shortcuts into a file

 <body>
<script src="framer/views.web_v2_feed_visual.js"></script>
<script src="framer/framer.js"></script>
<script src="framer/framerps.js"></script>
<script src="common.js"></script>
<script src="app.js"></script>
</body>

Framer JS

Quality prototyping for mobile and desktop

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store