Reputation: 379
I am trying to make a resizable and draggable div that is at a fixed position. The div looks fine when I resize it from the right or bottom; however, when I resize it from the left or top, the draggable div seems to increase height/weight in the opposite position.
Here is the code: HTML
<div id="draggableDiv" >
<div id="resizableDiv">
<div id="content"><div id="contentTitle"></div></div>
</div>
</div>
JS:
$('#draggableDiv').draggable({
handle: '#contentTitle'
});
$("#resizableDiv").resizable({
handles: 'n, e, s, w, ne, se, sw, nw'
});
CSS:
#draggableDiv {
position:fixed !important;
width:auto;
height:auto;
left:100px;
top: 100px;
}
#resizableDiv {
height: 200px;
width: 200px;
}
#content { height:100%; width:100%; }
What should I do to make the draggable div resizes itself correctly?
Upvotes: 0
Views: 2921
Reputation: 144
You can apply the jquery draggable & resizable to the parent container, this works fine.
$('#draggableDiv').draggable({
handle: '#contentTitle'
}).resizable({
handles: 'n, e, s, w, ne, se, sw, nw'
});
BTW I did a Jsfiddle where you can check that
http://jsfiddle.net/kQtMF/
Upvotes: 1
Reputation: 11671
You need to make the outer container #draggableDiv
resizable. If you do that, then it is also required to modify your css a bit to set this div the desired dimensions. For example,
html
<div id="draggableDiv">
<div id="resizableDiv">
<div id="content">
<div id="contentTitle">content title</div>
conteeeeeent
</div>
</div>
</div>
js
$('#draggableDiv').draggable({
handle: '#contentTitle'
});
$("#draggableDiv").resizable({
handles: 'n, e, s, w, ne, se, sw, nw'
});
css
/*colors were added for the example to separate each div*/
#draggableDiv {
position:fixed !important;
width:auto;
height:auto;
left:100px;
top: 100px;
background-color:green;
height:200px;
width:200px;
}
#contentTitle{
background-color:red;
cursor:move;
}
#resizableDiv {
height: 100%;
width: 100%;
}
#content {
height:100%;
width:100%;
background-color:blue;
}
Upvotes: 1