2016-08-17 184 views
2

我有以下设置:如何根据其他div高度自动更新div高度?

<div class="row"> 
    <div class="col-xs-6"> 
    <div id="first"> 
    </div> 
    </div> 
    <div class="col-xs-6"> 
    <div id="second"> 
    </div> 
    </div> 
</div> 

其中,DIV ID为first具有height属性设置为auto。我希望能够自动检测ID为first的div的高度变化,并将div的高度设置为secondx-70px,其中x是div的高度first

我该怎么做?

+0

确定事件,函数等改变它的高度并在那里添加@Wowsk答案。 '$(“#second”)。height($(“#first”)。height());' –

回答

1

使用jQuery将第二个div的高度设置为第一个div的高度。

$("#second").height($("#first").height()); 
+0

当第一个div的高度发生变化时,这似乎不会更新。 – uksz

+0

你怎么改变第一个div的高度?你有没有现场的例子? – Wowsk

+0

它根据显示在其中的元素的数量自动更改。 – uksz