4

I have this code:

<table>
    <tr>
        <td id="parent">
            <div id="child"></div>
        </td>
    </tr>
</table>

My JavaScript code:

$('#child' ).resizable({
    animate: true,
    helper: '.ui-resizable-helper',
    maxWidth: 500,
    maxHeight: 500,     
    aspectRatio: true
});

With the above code, My resizable div works as expected but when I add containment option, the divs width and height is resize to 0, when resize in whatever direction.

   $('#child' ).resizable({
        animate: true,
        helper: '.ui-resizable-helper',
        maxWidth: 500,
        maxHeight: 500,     
        aspectRatio: true,
        containment: '#parent'
    });

Why is it happening? Is it a bug?

3 Answers3

2

Try to add this CSS:

#parent {
  width: 500px;
  height: 500px;
}
Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
Niketan Raval
  • 479
  • 2
  • 10
2

The issue isn't with the #parent it's with the #child. Apply the following CSS so that it has a base start size.

#child {
  height:200px;
  width:200px;
}

Also you can see my fiddle here to illustrate the change using your code.

Huginn
  • 480
  • 2
  • 6
  • 21
  • My child already had height and width. Your answer doesnt work with me :( –  May 04 '16 at 06:08
  • 1
    @Eliyah so to be clear both your child and parent div have height specified in px – codefreaK May 04 '16 at 12:32
  • 1
    As @SachinDivakar stated. I didn't call out the other since it'd already been called out. With the update of both it works just fine with the code you've provided. If you're having further issues, please provide a fiddle with all of the code you're using so we can see if anything is combatting what we've been providing. – Huginn May 04 '16 at 13:02
  • 2
    @Eliyah dont waste hard earned reputation as bounty points without proper details in question .You lost your points and if you are not providing details enough to solve your problem what purpose does it server ?.If this does not work I say report it to jqueryUI and get a ticket – codefreaK May 04 '16 at 13:21
2
<table>
    <tr>
        <td>
            <div class="child" style="border:solid 1px red;">
            </div>
        </td>
                <td>
            <div class="child" style="border:solid 1px red;">
              <p>this is a test
            </p>
            </div>
        </td>
    </tr>
</table>

Define a minimum width and height for the child

.child {
 min-width:50px;
 min-height:50px;
}

Set containment to document and add the default minHeight, minWidth values.

  var defaultHeight = $('#child').height();
  var defaultWidth = $('#child').width();
 $('.child').resizable({
        animate: true,
        helper: '.ui-resizable-helper',
        minHeight:defaultHeight,
        minWidth:defaultWidth,
        maxWidth: 500,
        maxHeight: 500,     
        aspectRatio: true,
        containment: 'document'
    });

fiddle