10

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

2 Answers 2

31

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" );
Sign up to request clarification or add additional context in comments.

2 Comments

This is not what I meant. I only wanted it to "scroll" vertically and it can move horizontally. The question has already been answered but Thanks for the answer though.
this was just the thing I was looking for
13

You can use the containment option (doc) on the draggable elements. This way you can constrain their movement into the BODY element:

$('.draggable').draggable({
    ...
    containment: 'body',
    ...
});

DEMO

7 Comments

But I can't drag it down to the droppables.
Sure you can (or I don't get exactly the problem). The body will still scroll its viewport but will no extend if the cursor goes too far bottom or right.
The problem now is that the body doesn't go all the way to the bottom.
It looks like @Didier Ghys solution works fine, just tested it in your fiddle.
@Didier Ghys I figured it out... The reason it is being blocked is because those elements at the bottom are either fixed or absolute position not causing the body to expand it's height. This was not a problem in my live version but I had a div with a set height which grew bigger than that height so I removed the height and it now workds. Thanks for the help.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.