【问题标题】:Jquery same height depending on another divs heightJquery相同的高度取决于另一个div的高度
【发布时间】:2016-05-20 18:22:17
【问题描述】:

您好,我有一个问题,如何根据内容使所有 div 的高度始终相同(使用 .height-fix 类)。简单地说,如果我向一个 div 添加更多内容,其余的会调整它们的高度。

http://codepen.io/anon/pen/wGLmdb

var maxHeight = 0;
  $(".height-fix").each(function(index){
    if($(this).height() > maxHeight) {
        maxHeight = $("this").height();
    }
  });

  $(".height-fix").height(maxHeight);
  console.log(maxHeight);


    <div class="container">
          <div class="row">

            <div class="col-xs-3">
              <div class="jumbotron height-fix">
                <p>lorem lorem lorem lorem lorem lorem</p>
              </div>
            </div>

            <div class="col-xs-3">
             <div class="jumbotron height-fix">
                <p>lorem</p>
                <p>lorem lorem lorem lorem lorem lorem</p>
              </div>
            </div>

            <div class="col-xs-3">
              <div class="jumbotron height-fix">
                <p>lorem</p>
              </div>
            </div>

            <div class="col-xs-3">
              <div class="jumbotron height-fix">
                <p>lorem</p>
                <p>lorem lorem lorem lorem lorem lorem</p>
                <p>lorem lorem lorem lorem lorem lorem</p>
              </div>
            </div>

          </div>

        </div>

【问题讨论】:

  • 我认为您选择了错误的工具。它可以通过 CSS3 轻松实现,使用flexboxes

标签: jquery html height


【解决方案1】:

换行

maxHeight = $("this").height();

maxHeight = $(this).height();

【讨论】:

  • wtf :D 我很想念它谢谢你
【解决方案2】:

我只是稍微修改一下你的代码。

codepen 上的 DEMO

var maxHeight = 0;
$(".height-fix").each(function(index){
if($(this).height() > maxHeight) {
maxHeight = $(this).height();
}
});

$(".height-fix").height(maxHeight);

【讨论】:

    猜你喜欢
    • 2014-06-22
    • 2012-12-03
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多