【问题标题】:Set same height across different divs issue在不同的 div 问题上设置相同的高度
【发布时间】:2015-11-18 22:24:59
【问题描述】:

我有这段脚本,它计算出高度最大的 div,并将其设置为我选择的所有其他 div。效果非常棒。但问题是,这种方法似乎包括隐藏的 div(用于计算高度)。这是众所周知的事情吗?我尝试添加过滤器(:可见)无济于事。

var windowWidth = $j(window).width();
$j.fn.setAllToMaxHeight = function() {
    return this.height(Math.max.apply(this, $j.map(this.children().filter(':visible'), function(e) { 
        return $j(e)[0].scrollHeight;
    })));
};

【问题讨论】:

    标签: jquery height equals


    【解决方案1】:

    你可能想这样写:

    $j.map(this.filter($j('> :visible', this))
    

    【讨论】:

      【解决方案2】:

      你可以试试这个:

      var maxHeight = -1;
      $('div').each(function() {
          if ($('div').is(':visible') && $('div').height() > maxHeight)
          maxHeight = $(this).height();
      });
      $('div').each(function() {
          $(this).height(maxHeight);
      });
      

      【讨论】:

        猜你喜欢
        • 2011-01-29
        • 1970-01-01
        • 2021-04-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-04
        • 1970-01-01
        • 2016-12-23
        相关资源
        最近更新 更多