javascript - JqueryUI Draggable - Auto resize parent container - Stack Overflow

I have two divs, one within the other. The outer div (the container) is of arbitrary dimensions. The in

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.

I have applied jquery draggable to the inner div and I'm looking to automatically resize its parent container when I drag the inner div past the outer edges of the container. How can I go about doing this?

I see a similar feature here on StackOverflow when asking a new question. The textarea for typing in a question has a div named 'grippie' which resizes the textarea. This is exactly the functionality I'm looking for, but with a div instead of a textarea.

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.

I have applied jquery draggable to the inner div and I'm looking to automatically resize its parent container when I drag the inner div past the outer edges of the container. How can I go about doing this?

I see a similar feature here on StackOverflow when asking a new question. The textarea for typing in a question has a div named 'grippie' which resizes the textarea. This is exactly the functionality I'm looking for, but with a div instead of a textarea.

Share Improve this question asked Feb 16, 2011 at 21:18 RichardRichard 3571 gold badge4 silver badges5 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Here you go. Works both horizontally and vertically. See it in action at http://jsfiddle/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);
        }
    }
});

You can use the drag function that es with jquery draggable. In the drag function you can just check if the edges of the inner div is outside of the container div's edges.

If thay are, increase the width or height of the container div.

You can use the position method that is native in jquery ui to check for positions of top,bottom,left and right of both div tags.

Here are links to the api for more detailed information about how these methods work.

  1. Draggable->event->drag
  2. Position

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744791259a4593928.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信