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

What is Framer? Join the Community
Return to index
Diogenes Brito
Posted Jun 29 - Read on Facebook

Has anyone been able to limit dragging to only one direction successfully? The DragMove event doesn't seem to fire often enough to keep the layer in the right place. Instead I can drag anywhere and it will periodically snap back to the right place.

Here's a sample to try in Framer Studio:
```
myLayer = new Layer
x: 0
y: 100
width: 100
height: 100

myLayer.draggable.enabled = true

myLayer.on Events.DragMove, (event) ->
myLayer.y = 0
```

6 Comments

Peter Hui

You can set myLayer.draggable.speedX = 0 to make it drag along y-axis, and vice versa.

Diogenes Brito

Aha, just saw that in this post: https://medium.com/@gem_ray/prototyping-swipe-and-drag-gestures-with-framer-3-2e405d50b600

Now, I want to limit the X value to a max and min, and have it snap to either end, anyone know how that might work?

Jason Najarro

I was similarly trying to limit drag movement. After going through a couple different examples I put together this:

initX = 0

PSD.grabme.on Events.DragStart, (event) ->
initX = event.x

PSD.grabme.on Events.DragMove, (event) ->
deltaX = initX - event.x
if deltaX < MAX || deltaX > MIN
PSD.grabme.draggable.enabled = true
else
PSD.grabme.draggable.enabled = false

Ed Nepomuceno

This seems to work for me:

myLayer1.draggable.maxDragFrame = myLayer2.frame

Diogenes Brito

Where is maxDragFrame documented? That's handy.

Francesco Fiore

Hey guys, there is a nice way to limit drag in one direction:

myobject.draggable.speedY = 0

Just set the speed of X or Y to zero and thats done.

Read the entire post on Facebook