Resize elements by dragging divider handler

前端 未结 3 676
一向
一向 2020-12-16 08:34

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

3条回答
  •  时光取名叫无心
    2020-12-16 09:06

    In case anyone is interested in the future, I got it to work nicely with this:

    $('.rsh').draggable({
        axis: 'y', 
        containment: 'parent',
        helper: 'clone', 
        drag: function (event, ui) { 
            var height = ui.offset.top - 85; 
            $(this).prev().height(height); 
        } 
    });
    

    This is the fiddle.

    The use of clone is the key. The draggable elements (.rsh) are relative, so if you don't use a clone the element moves twice as far as the mouse because it is also affected by the change in the height of the previous div.

    Note: The - 85 is just a quirk of the page layout making allowance for the header and so forth.

提交回复
热议问题