Demoralizes to see downvotes, I really did my best (I believe) to explain my issue and keep it short and simple. If you find hard to understand the question I’m willing to follow-up with any improvement suggestions :,(
I’m trying to create a 100% height vertical sidebar that has N number of resizable children elements – something like Facebook sidebar (chat…) or Photoshop’s sidebar
where the children do not exceed the parent height and resizing one element the other should resize accordingly, so practically the added children heights should always match the (100%) parent height.
I tried to resize table rows but again without success…
This what I have so far using CSS3 flex (seemed like a good idea) 🙁
$("#panel>div").resizable({
handles:'s' /* try using "n" to see what happens... */
});
*{margin:0; box-sizing: border-box;}
html, body{height:100%;}
[class^=ui-resizable]{height:2px;background:#08f;cursor:row-resize;}
#panel{
display:flex;
flex-direction: column ;
height:100%;
width:200px;
}
#panel>div{
flex: 1;
background:#aaa;
}
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<div id="panel">
<div id="a">a</div>
<div id="b">b</div>
<div id="c">c</div>
</div>
You can clearly see in the above demo that due the use of flex
jQuery is unable to resize the elements….
How would you approach to this problem (without plugins)? thanks
2
Answers
CSS3 flexboxes aren’t very well supported and might not be very well suited to this task. Set resize: vertical on the elements and use a javascript listener to resize all of your divs when one is resized. I don’t know how specifically you want to implement resizing and I don’t have the patience to write something that involved from scratch for no pay, but what I can offer you is a little javascript that might help you add event listeners to all of the elements of a class.
Turned out i had some time after all 🙂 fiddle
So key code in this is that when you start resizing you select a neighbour you also want to resize as such:
And store it’s height. Then when we resize, we also resize the other one as such
Hope that works for you