My page has several items (divs) that are draggable and resizable.
My code for doing this is given below:
part.draggable(
{
containment: 'parent',
drag: function(event, ui){
partIsDragging = true
part.prev().css('top', ui.position.top - 20 ).css('left', ui.position.left )
part.prev().show()
},
stop: function(event, ui) {
partIsDragging = false
}
}).resizable({
containment: 'parent',
handles: 'ne, se, sw, nw,n,w,e,s',
stop: function() {
}
});
The html structure for these is the following:
<body>
<div id="wrapper">
<div class="draggableItem"></div>
<div class="draggableItem"></div>
<div class="draggableItem"></div>
<div class="draggableItem"></div>
</div>
</body>
In my css files i have set body height: 100% and wrapper height: 100%. Width is always fixed for wrapper, width: 950px. I want my div to expand in height when the draggableItem reaches the bottom of the wrapper. Right now when the page is loaded, it has the height as big as the resolution allows it but in case I have more items in the wrapper then everything becomes cluttered and I would like when dragging an item to somehow expand the wrapper in height dynamically. This should happen only if I hit the bottom border.
PS: I am using jQuery and jQuery-ui.
I may have a solution. First off, I replaced
partwith'.draggableItem'andthiswhere appropriate. Please tell me if that breaks the code in some critical way. In addition, I removedpart.prev().css('top', ui.position.top - 20 ).css('left', ui.position.left )in the code below.The function
adjustWrapperHeight(movingObject)adjustsdiv#wrapper‘s height depending on amovingObject‘s bottom position. That is, whenmovingObject“pushes up” againstdiv#wrapper‘s borders, it adjustsdiv#wrapper‘s height.I had to use a hack for
resizable. Thecontainment: 'parent'forresizable(but notdraggable) sets the containment to the container’s ORIGINAL height or so it seems. That means as the height ofdiv#wrapperdynamically changes, the constraint set bycontainment: 'parent'does not dynamically change. To fix this, I removedcontainment: 'parent'and indeed the entirecontainmentand ensured thatdiv#wrapper‘s right containment isn’t broken within theresizeevent. Note that you should probably do this withdiv#wrapper‘s left containment as well.Please tell me if this was helpful. Thank you.