jQuery Draggable and overflow issue

Jquery UiDrag and-Drop

Jquery Ui Problem Overview


I am having an undesired effect when I drag a div from a container div which is set as overflow: scroll.

I have found an example of someone else where they have had the issue but I have been unable to find a resolution

Example on Paste bin

What happens is that the scroll is just increased, I can see why this would be the desired behaviour if you wanted to drag to a destination within the scrollable div but I want to be able to take it outside of its scrolling grasp.

Jquery Ui Solutions


Solution 1 - Jquery Ui

I had a similar problem enabling a drag between two overflow-auto divs. With the help of the previous answers, I found that this combination works for me (Safari 5.0.3, jquery-1.4.4, jquery-ui-1.8.7):

appendTo: 'body',
containment: 'window',
scroll: false,
helper: 'clone'

Solution 2 - Jquery Ui

appendTo

Element, SelectorDefault:'parent'

The element passed to or selected by the appendTo option will be used as the draggable helper's container during dragging. By default, the helper is appended to the same container as the draggable.

Code examples Initialize a draggable with the appendTo option specified.

$('.selector').draggable({ appendTo: 'body' });

Solution 3 - Jquery Ui

It certainly pays to pay attention to the documentation

http://docs.jquery.com/UI/Draggable#option-scroll

> ### scroll > > Type: Boolean
Default: true
If set to true, container auto-scrolls while dragging.

All who enter here, learn from my mistake, RT(F)M!!!

Solution 4 - Jquery Ui

The clone solution it works, but has two problems.

First: the clone are append to the body. Depending of your css, your element can change the styles, since before it starts, it's inside of another element and during the dragging, it will be directly on body element.

Second: Sometimes the element MUST move, and the clone let the object there.

So, the solution for this problems is:

$('.selector').draggable({
	helper: 'clone',
	start: function(){
		$(this).hide();				
	},
	stop: function(){
		$(this).show()
	}
});

Solution 5 - Jquery Ui

Setting the scroll option does not stop children from being hidden in the overflow area. I have come up with a work-a-round that uses the helper option. Check it out:

http://pastebin.me/164f0a4073496563fe3179ddcec5fd6d

Also here is a reference to another post I made:

https://stackoverflow.com/questions/2098387/jquery-ui-draggable-elements-not-draggable-outside-of-scrolling-div/2099100#2099100

Solution 6 - Jquery Ui

You can also specify which types of elements you don't want to include.

<div class="draggable"> 
    <h2>This will drag the div</h2>
    <ul>
       <li>This won't drag the div</li>
    </ul>
</div>

Apply this cancel property to ignore the event in specified child elements

$('.draggable').draggable({cancel : 'ul'});

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPhill DuffyView Question on Stackoverflow
Solution 1 - Jquery Uimarks_View Answer on Stackoverflow
Solution 2 - Jquery UiChad GrantView Answer on Stackoverflow
Solution 3 - Jquery UiPhill DuffyView Answer on Stackoverflow
Solution 4 - Jquery UiBruno GuaitaneleView Answer on Stackoverflow
Solution 5 - Jquery UiJustin BullView Answer on Stackoverflow
Solution 6 - Jquery Uicolin-higginsView Answer on Stackoverflow