JqueryUI Draggable - Auto resize parent container

后端 未结 2 696
我在风中等你
我在风中等你 2020-12-21 04:16

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.

2条回答
  •  难免孤独
    2020-12-21 04:43

    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);
            }
        }
    });
    

提交回复
热议问题