Skip to content

Instantly share code, notes, and snippets.

@mrrocks
Last active August 29, 2015 14:15
Show Gist options
  • Save mrrocks/8bc1ce7c2070c69a650e to your computer and use it in GitHub Desktop.
Save mrrocks/8bc1ce7c2070c69a650e to your computer and use it in GitHub Desktop.
Draggable layer with inertia and boundaries in FramerJS
ACCELERATION = 180
INERTIA_CURVE = "spring(140, 30, 0, 0)"
Layer::inertia = ->
calculateFinalY = =>
newY = @y + @draggable.calculateVelocity().y * ACCELERATION
switch
when newY > 0 then return 0
when newY + @height < Framer.Device.screen.height then return -@height + Framer.Device.screen.height
else return newY
@animate
properties: y: calculateFinalY()
curve: INERTIA_CURVE
# layerName.on Events.DragEnd, -> @inertia()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment