Skip to content

Instantly share code, notes, and snippets.

@carambula
carambula / Framer Style Demo
Created November 11, 2013 00:34
Fun with Framer styling
// Set up our views
myStream = new View({x: 0, y: 0, width: 320, height: 568})
myStory = new View({
x: 10,
y: 10,
width: 300,
height: 160,
html: "Hello world"
})
@carambula
carambula / Framer rotateJankFIx
Last active December 27, 2015 20:49
Framer demo based on Craig Murray's question in the Framer JS Facebook group: https://www.facebook.com/groups/framerjs/permalink/416670385126705/
var picRef = new ImageView({
x:100,
y:100,
width:400,
height:300,
image: "http://distilleryimage7.ak.instagram.com/310adf44426011e38fa722000a9f1885_8.jpg"
});
var turnLeft_BTN = new View({
x:4,
@carambula
carambula / Framer convertPoint
Last active December 27, 2015 20:49
Example of Framer JS's convertPoint utility in use.
//DEMO: drag the childView inside the box and click the view outside to send it to the relative location of the inner one.
// set up three views, one to hold a child and two that match except for their superViews
parentView = new View({x: 100, y:100, width: 300, height: 300})
childView = new View({x: 20, y: 20, width: 60, height: 40, superView: parentView})
cousinView = new View(childView)
cousinView.superView = parentView.superView
childView.dragger = new ui.Draggable(childView)
cousinView.on("click", function(){
@carambula
carambula / Framer utils.cycle
Last active December 27, 2015 20:09
Demo for Framer Cycle utility
/// Test view setup
view = new View({x:50,y:50,width:100,height:100})
// Define the functions to cycle through
// Create cycle variables.
var scales = utils.cycle(.3, .6, 1, 1.3, 1, .6)
var coords = utils.cycle({x: 250, y:50}, {x: 250, y:250}, {x: 50, y:250}, {x:50, y:50})
var rotations = utils.cycle(-90,45,-110,180,0)
@carambula
carambula / convertRange
Created October 31, 2013 08:58
Convert a number within a range to a different range. For instance, 3 on a 1-10 scale to a 1-100 scale. Handy for pegging something like alpha (0-1 range) to an x coordinate (0-width of space)
function convertRange(OldMin, OldMax, OldValue, NewMin, NewMax){
var OldRange = OldMax - OldMin;
var NewRange = NewMax - NewMin;
return (((OldValue - OldMin) * NewRange) / OldRange) + NewMin;
}
newOpacity = convertRange(0, 10, 3, 0, 100)
console.log (newOpacity)
@carambula
carambula / framer getChildView
Last active December 26, 2015 23:18
Framer.js function for getting a child view by partial name match. Not great if it finds more than one result.
// Simple get child function by partial name match
// useful for photoshop files with repeated layer group naming
function getChildView(view, needle){
haystack = view.subViews
for (var hay in haystack){
if (haystack[hay].name.indexOf(needle) !== -1){
return view.subViews[hay]
}
}
}
@carambula
carambula / gist:7201506
Created October 28, 2013 17:59
Demo of scaling weirdness while dragging in framer. Help!
cell = new View({
x: 0,
y: 300,
width: 640,
height: 100
});
cell.dragger = new ui.Draggable(cell);
cell.animated = false;
cell.on(Events.DragMove, function() {
@carambula
carambula / Move the subviews
Last active December 22, 2015 08:29
Quick sketch for looping through child views. Not the cleanest but works. Fork if you got somethin better!
// Set up the views. One big view and several smaller views. I'm using a shortcut to make all the subViews the same as the first
parentViewA = new View({x:10,y:10,width:500,height:500})
subView1 = new View({x:0,y:0,width:50,height:50})
subView1.superView = parentViewA
subView2 = new View(subView1)
subView3 = new View(subView1)
subView4 = new View(subView1)
subView5 = new View(subView1)
subView6 = new View(subView1)
@carambula
carambula / Framer Class Loop
Created August 16, 2013 19:43
With Framer, I often need to access a class of views like "all of the views that scroll" or "all of the profile pics". Here's how I do it: 1. In Photoshop, I name all of the layergroups I want access to with a keyword. ie: Highlights 2013 FramerPager Photos 2013 FramerPager Highlights 2012 FramerPager (see a pattern? This is both good naming AND…
for (var layerGroupName in PSD) {
view = PSD[layerGroupName];
// Change FramerPager here to your keyword
if (view.name.indexOf("FramerPager") != -1){
// do something with that thing!
// one idea is to add it to an array for access later
// or you cold set their css style, set their positions, whatever
// in the demo below I make a new FramerPager for it so it… pages
}
}
@carambula
carambula / responsive_block_mixin.sass
Created November 2, 2012 21:56
Manage blocks of responsive attributes more cleanly
@mixin responsive-block($breakpoint: null)
@if $breakpoint == wide
@media only screen and (min-width: 1280px)
@content
@if $breakpoint == ipad-landscape
@media only screen and (min-width: 1024px) and (max-width: 1124px)
@content
@if $breakpoint == ipad-portrait
@media only screen and (min-width: 768px) and (max-width: 1024px)
@content