http://jsfiddle.net/LakYy/5/
$(document).ready(function() { var $document = $(document), $parent = $("#parent"), $container = $(".container", $parent), offset = $container.offset(), scrollbarSafety = 15; $container.height($document.height() - offset.top - scrollbarSafety); $("#eleman,#eleman2") .draggable( { containment: $container, drag: function(event, ui) { var shouldHeight = getdraggablemaxheight(); if($parent.height() < shouldHeight) { $parent.height(shouldHeight); } if($parent.height() > shouldHeight) { $parent.height(shouldHeight); } } } ); }); function getdraggablemaxheight() { var $parent = $("#parent"), $container = $(".container", $parent), maxheight = 0, currentheight = 0, currentposition; $container.children().each(function(index, element) { currentposition = $(element).position(); currentheight = currentposition.top + + $(element).height() + 15; if(currentheight > maxheight) maxheight = currentheight; }); return maxheight;
source share