I have two divs, one within the other. The outer div (the container) is of arbitrary dimensions. The inner div is set to a specified dimension smaller than its container. >
Here you go. Works both horizontally and vertically. See it in action at http://jsfiddle.net/evunh/1/
var i = $('#inner');
var o = $('#outer');
i.draggable({
drag: function(event, ui) {
if (i.position().top > o.height() - i.height()) {
o.height(o.height() + 10);
}
if (i.position().left > o.width() - i.width()) {
o.width(o.width() + 10);
}
}
});