在父级高度内垂直调整DIV元素的大小 [英] Vertically resize DIV elements within parent height

查看:53
本文介绍了在父级高度内垂直调整DIV元素的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为看到沮丧的投票而感到沮丧,我确实尽我所能(我相信)来解释我的问题,并使其简短而简单.如果您发现难以理解的问题,我愿意提出任何改进建议:,(

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 :,(

我正在尝试创建一个高度为 100%高度的垂直边栏,其中包含N个可调整大小的子元素元素-类似于Facebook边栏(聊天...)或Photoshop的侧边栏

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

如果子代的高度不超过父代的高度,而另一个元素的大小要相应调整,则实际上增加的子代高度应始终与父代的高度(100%)相匹配.

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.

我试图调整表行的大小,但是又没有成功...
到目前为止,我使用 CSS3 flex (似乎是个好主意):(

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>

您可以在上面的演示中清楚地看到,由于使用flex,jQuery无法调整元素的大小....

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

推荐答案

原来我毕竟有一段时间:) 小提琴

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:

if ($(this).next('.resiz').length>0){
    other= $(this).next('.resiz');
 }else{
    other = $(this).prev('.resiz');
 }
 startingHeight= other.height();

并存储它的高度.然后,当我们调整大小时,我们也调整了另一个大小

And store it's height. Then when we resize, we also resize the other one as such

 resize:function(e,ui){
     var dh = ui.size.height-ui.originalSize.height;
     if (dh>startingHeight){// can't resize the box more then it's neighbour
         dh =  startingHeight;
         ui.size.height = ui.originalSize.height+dh;
     }
     other.height(startingHeight-dh);
 }

希望对您有用

这篇关于在父级高度内垂直调整DIV元素的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆