Framer and CoffeeScript 1 Flashcards
What does @ symbol mean in CoffeeScript?
CoffeeScript has a few nice features related to the this keyword.
- First, CoffeeScript uses the @ symbol as shorthand for “this.”. For example, @foo is equivalent to this.foo.
- Second, if you use the @ symbol in the parameters of a function, CoffeeScript will automatically assign those values as properties of the object.
How to import (from Sketch into Framer) an asset with some transparent padding? (2 techniques)
- Export it manually in the images folder with the transparency (using “slices” for example)
- Use a mask in Sketch that is bigger than the element to mask (so that it will generate the padding around the element). Then, the Framer import function will consider this layer as a whole (need to be a group in Sketch).
How to print the properties of myObject?
for… of (“key” and “value” are just conventional words that you can change)
Illustrate what are x and y for an object
Illustrate what is midX
Illustrate what is midY
Illustrate what are minX and minY
Illustrate what are maxX and maxY
Another keyword can be used for that
unless
What should be the value for the else condition to work?
==21
Which property allows you to set or capture the x, and y values of a layer?
layer.point
Which property allows you to set or capture the width and height values of a layer?
layer.size
Which property allows you to set or capture the x, y, width and height values of a layer?
layer.frame
Which property gets or sets all properties for a layer?
layer.props
Which shortcut to quickly display documentation in Framer?
cmd + d
How to deactivate click when scrolling on elements that are clickable otherwise?
(because we touch elements when scrolling)?
if not scroll.isMoving
How to prevent a draggable element which also contains a scroll from doing both interaction at the same time?
(Usually, we don’t scroll while dragging)
layer.draggable.directionLock = true
Are invisible/hidden Sketch layers imported into Framer?
Yes, as long as they’re inside a group. Their visibility is set to false inside Framer
How does Framer handle Sketch’s artboards?
Based on the most left artboard.
The x and y properties of the most left artboard on your canvas will be set to 0, 0. All other artboards are positioned relative to this one.
How to simulate a @2x rendering from a @1x Sketch import?
(Can cause a slight blur rendering)
Framer.Device.contentScale = 2
Inside a loop, each time an element is created, can we store it inside an array?
Yes. We can add these lines:
Before/outside the loop, we declare the array
myArray = []
(…)
We add to the array
myArray.push(nameOfInstance)
or see below capture for more options
How to easily get/edit most of the CSS properties of layers ?
(-> which layer member is it and which naming convention for the properties?)
layer.style
Next to the standard CSS property names (string) you can also camelCase naming.
How to edit the border of layerA ? (2 ways)
- layerA.style[“border”] = “1px solid red”
- layerA.style.border = “1px solid red”
Give two ways to edit the border color of layerA
- layerA.style[“border-color”] =
- layerA.style.borderColor =
How to edit several style properties of layerA?
layerA.style =
“outline”: “1px solid red”,
“padding”: “10px”
How to print a specific style property ?
(like layerA’s outline or box-shadow)
- print layerA.style[“outline”]
- print layerA.style.outline
- print layerA.style[“box-shadow”]
- print layerA.style.boxShadow
When crafting animations, why is it often better to base a function on a layer.property expression (ex: sth = layerA.height) instead of on the actual value of this property ?
Because if we update the layer (in Sketch or by overwriting later in the code), the actual value will be outdated. Relative values are often better.
What allows you to set or capture the absolute position of a layer on the screen, ignoring the inherited position from its parents ?
layer.screenFrame <object></object>
What type of data do we get if we print layer.subLayers?
An array
layer.subLayers <array></array>
What is the difference between the first technique and the 2 others?
In the first case, items created inside the loop just get assigned a name and some properties but aren’t stored inside a variable, so we cannot play with them separately afterwards and do something like print(item1)
What is this:
layer.draggable.speedX <number></number>
Modify the horizontal dragging speed. The value is in pixels per mouse moved pixels. The default value is 1. When set lower then 1 dragging will be slower than mouse movement and vice versa. You can set the value to 0 to disable horizontal dragging.
What is this:
page.snapToPage(page, animate, animationOptions)
Snap to a specific page. Takes three arguments:
- a page.content layer
- animate (true or false)
- animation options
By default, animate is set to true and the animationCurve use a spring curve.
layerA = new BackgroundLayer
What is the specificity about BackgroundLayers concerning the fill ?
BackgroundLayers always fill the entire canvas no matter where they’re displayed
How to set the constraints of a draggable layer ?
Ex. 1:
layerA.draggable.constraints = { x: 0, y: 0, width: 200, height: 200 }
Ex. 2 (relative to another element):
layerA.draggable.constraints = layerB.frame
How to declare that a layer cannot be dragged over the constraints defined previously?
layerA.draggable.overdrag = false
Note that the layer can still get over the constraints with momentum.