I am trying to get the new size of a div after resizing. However when using ui.size.height
or $(e.target).height()
I am getting instead the original height of the element.
JavaScript
x
16
16
1
function allowResizing(el){
2
$(el).resizable({
3
animate: true,
4
containment: "parent",
5
helper: "ui-resizable-helper",
6
minWidth: 250,
7
minHeight: 250,
8
grid: [20, 20],
9
stop: function( e, ui ) {
10
console.log("height: " + $(e.target).height())
11
console.log("height: " + ui.size.height)
12
console.log("originalHeight: " + ui.originalSize.height)
13
}
14
});
15
}
16
All three logs write the same value. When I try this code on any other div on another page I get the right values.
My hmtl:
JavaScript
1
31
31
1
<style>
2
.containment-wrapper > .row{
3
border: 3px solid white;
4
width: 100%;
5
height: calc(100vh - 200px);
6
min-height: 200px;
7
position:relative;
8
}
9
10
.ui-resizable-helper {
11
border: 2px dotted #b1b1b1;
12
}
13
</style>
14
15
<div class="containment-wrapper">
16
<div class="row">
17
<div id="resizable" class="ui-draggable ui-draggable-handle" style="position: absolute !important; outline: 1px solid white;">
18
<div class="Container_Header">
19
<span style="display: block; padding: 0 10px" class="Text_H2">$title</span>
20
</div>
21
<p style="padding: 10px">
22
Some text
23
</p>
24
</div>
25
<script type="text/javascript">
26
allowResizing("#resizable")
27
</script>
28
</div>
29
</div>
30
31
I also use ui.Draggable on the same element but also tried without it.
Appreciate every help. Thank you
Advertisement
Answer
Since you have defined a Helper, you will want to review the Size of that element.
JavaScript
1
32
32
1
$(function() {
2
function allowResizing(el) {
3
$(el).resizable({
4
animate: true,
5
containment: "parent",
6
helper: "ui-resizable-helper",
7
/*
8
minWidth: 250,
9
minHeight: 250,
10
grid: [20, 20],
11
*/
12
resize: function(e, ui) {
13
log("Height: " + ui.size.height);
14
},
15
stop: function(e, ui) {
16
log("El height: " + $(ui.element).height());
17
log("Stop height: " + ui.size.height);
18
log("Original Height: " + ui.originalSize.height);
19
log("Helper Height: " + ui.helper.height());
20
}
21
});
22
}
23
24
function log(str) {
25
var log = $("#log").length ? $("#log") : $("<div>", {
26
id: "log"
27
}).appendTo("body");
28
log.append(`<p>${str}</p>`).scrollTop(log.prop("scrollHeight"));
29
}
30
31
allowResizing("#resizable");
32
});
JavaScript
1
22
22
1
.containment-wrapper>.row {
2
border: 3px solid white;
3
width: 100%;
4
height: calc(100vh - 200px);
5
min-height: 200px;
6
position: relative;
7
}
8
9
.ui-resizable-helper {
10
border: 2px dotted #b1b1b1;
11
}
12
13
#log {
14
font-size: 65%;
15
height: 4em;
16
overflow: auto;
17
}
18
19
#log p {
20
padding: 0;
21
margin: 0;
22
}
JavaScript
1
15
15
1
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
2
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
3
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
4
<div class="containment-wrapper">
5
<div class="row">
6
<div id="resizable" style="position: absolute !important; outline: 1px solid white;">
7
<div class="Container_Header">
8
<span style="display: block; padding: 0 10px" class="Text_H2">$title</span>
9
</div>
10
<p style="padding: 10px">
11
Some text
12
</p>
13
</div>
14
</div>
15
</div>