Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery UI Resizable + box-sizing: border-box = height bug?

I'm trying to resize a DIV with box-sizing: border-box; Even though I only allow resizing the width, the DIV shrinks everytime the resize event stops (height changes).

My CSS

.test{
    width: 200px;
    height: 100px;
    border: 1px solid red;
    box-sizing: border-box;

}

Javascript

$(document).ready(function() {
    $('.test').resizable({handles: 'e', stop: function(event, ui){
        $('.wdt').text(ui.size.height);
    }});
});

HTML

<div class="test">
    Test
</div>
<br/>
<br/>
<span>Height =</span>
<span class='wdt'></span>

Resize it and you will see.

Can anybody help me? JSFiddle: http://jsfiddle.net/WuQtw/4/

I tried jquery 1.8.x.. 1.9.x... nothing changes. I cant use box-sizing: content-box.

like image 571
Fabio K Avatar asked Aug 20 '13 20:08

Fabio K


2 Answers

I don't know why it's happening, but it seems your border property is the issue.

If you want it to function the same, you can use outline instead.

http://jsfiddle.net/WuQtw/10/

.test{
    width:200px;
    height: 100px;
    outline:1px solid red;
    box-sizing: border-box;
}
like image 171
Christopher Marshall Avatar answered Oct 20 '22 07:10

Christopher Marshall


I just discovered the same problem and build this snippet - may it helps someone.

// initiate correction
var iHeightCorrection = 0;

var oElement = $('#elementToResize');

// init resize
oElement.resizable({
        handles: 's',
        minHeight: 30,
        // on start of resize
        start: function(event, ui) {
            // calculate correction
            iHeightCorrection = $(oElement).outerHeight() - $(oElement).height();
        },
        // on resize
        resize: function(event, ui) {
            // manual correction
            ui.size.height += iHeightCorrection;
        },
        // on stop of resize
        stop: function(event, ui) {
            // reset correction
            iHeightCorrection = 0;
        }
    });

Fiddle

like image 4
eXe Avatar answered Oct 20 '22 09:10

eXe