Jquery-ui draggable scroll vertical only

Caleb Doucet picture Caleb Doucet · Feb 7, 2012 · Viewed 19.9k times · Source

So I have a fixed droppable div in the bottom right of my screen. I have a list of draggables that can be dragged into the trash (the fixed droppable) but I don't want the horizontal scrollbar to appear when dragging them near the trash. I don't want the draggables to be able to scroll horizontally. There are other droppables further down on the page that they can be dropped into so they must scroll vertically to get to them.

Here is a jsfiddle of the the problem.

Thanks

Answer

Alejandro del Río picture Alejandro del Río · Mar 30, 2012

In order to only allow vertical dragging, you must set the "axis" property of the draggable this way:

$( "selector" ).draggable({ 
    axis: "y"
});

And if you already have an initialized draggable object, you must set it this way:

$( "selector" ).draggable( "option", "axis", "y" );