It seems that inside the jQuery user interface, they save the parent information at the beginning of the drag, so even if you change the size, it will still restrict the drag and drop.
To fix this, you can set your limiter.
$("#dragElement") .draggable({ cursor : "move", scroll : false, containment : [20, 20, 400+20, 1000], drag : function(event, ui) { expandParent("#parentElement", "#dragElement"); } }) .resizable({ containment : "parent", resize : function(event, ui) { expandParent("#parentElement", "#dragElement"); } }); function expandParent(parentName, childName) { var dragEl = $(childName); var dragElTop = parseInt(dragEl.css("top"), 10); var dragElHeight = parseInt(dragEl.css("height"), 10); var dragElBottom = dragElTop + dragElHeight; var parentEl = $(parentName); var parentElBottom = parseInt(parentEl.css("height")); if(parentElBottom <= dragElBottom + 20) { parentEl.css("height", dragElBottom+20); } }
With the above code, it will allow you to resize the parent to 1000 + 20 in height. You can try the above code here (JSFiddle) .
If you need to make a dynamic container, at the beginning (and in the resize method), install a new container with the correct BoundingBox.
var p = $("#parentElement"); var dragWidth = parseInt($("#dragElement").css('width')); var left = p[0].offsetLeft; var top = p[0].offsetTop; var width = parseInt(p.css("width"), 10)-dragWidth; var containment = [left, top, width+left, 1000];
Yes, I know that the solution is kind of hacky .. but in any case, I just updated JSFiddle. This solution may not be for calculating and reinstalling the dynamic size of the container. I just wanted JSFiddle to work beautifully.
wendelbsilva
source share