I want to be able to drag a divider up and down to resize the divs above and below the divider on a fixed page height. These divs could be in a table, although they need not
Here is another alternative to Nick's version, it automatically moves the horizontal handler to the top and to zero as a nice effect. Also, it adjusts the height size of both sections mutually.
$('.horizontal_handler').draggable({
axis: 'y',
containment: 'parent',
helper: 'clone',
drag: function (event, ui) {
var height = ui.offset.top - 220 // 220 : initial top margin to the previousDiv
, referenceHeight = nextDivHeight + previousDivHeight //500 px initial height size
, previousSection = $(this).prev()
, nextSection = $(this).next();
if ((nextSection.height() === 0) && (referenceHeight - height < 0)){
return;
}
previousSection.height(height);
nextSection.height(referenceHeight - height ) ;
if (nextSection.height()< 20){
previousSection.height( height+ nextSection.height() );
nextSection.height(0);
}
if (previousSection.height()< 20){
nextSection.height(referenceHeight - height - previousSection.height() );
previousSection.height(0);
}
}
});