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

What is Framer? Join the Community
Return to index
Kevin Cannon
Posted Oct 08 - Read on Facebook

How does scope work in Drag events? This doesn't reset the layer to the start location.

draggy = new Layer

draggy.on Events.DragStart, ->
startX = draggy.x
startY = draggy.y

draggy.on Events.DragEnd, ->
draggy.x = startX
draggy.y = startY

3 Comments

Andrew Nalband

Yep, that's a scoping problem. Those two dragging events you have there will become functions when compiled to JS. You need to declare startX=0 and startY=0 in the same scope you're declaring draggy

Jordan Robert Dobson

Or... One simpler way is to attach the value to the layer...

Inside your DragStart...

draggy.startPoint = draggy.point

Inside your DragEnd...

draggy.x = draggy.startPoint.x
draggy.y = draggy.startPoint.y

The point property is your friend.

Jordan Robert Dobson

Or.... Duh moment... In your DragEnd

draggy.point = draggy.startPoint

Read the entire post on Facebook