【问题标题】:jQuery add variablejQuery添加变量
【发布时间】:2012-07-12 13:40:37
【问题描述】:

我找到了一个脚本here,它可以使连续 div 的高度相等(引导程序)。例如,如何将 20 添加到它计算的新高度?

这是脚本和 jsFiddle: http://jsfiddle.net/MVP3C/

$('.well, .alert').height(function () {
    var h = _.max($(this).closest('.row').find('.well, .alert'), function (elem, index, list) {
        return $(elem).height();
    });
    return $(h).height();
});

【问题讨论】:

    标签: jquery


    【解决方案1】:

    试试下面的 sn-p:

    var HeightIncrement = 20; // the increment you need
    
    var h = _.max($('.row').
        find('.well, .alert'),
        function (elem, index, list) {
            return $(elem).height();
        });
    var maxHeight = $(h).height();
    
    $('.well, .alert').height(function () {
        return maxHeight + HeightIncrement;
    });
    

    本质上,只需要预先计算公共高度(maxHeight变量),然后以递增的公共高度值运行.height(...)函数。

    http://jsfiddle.net/pJ8zQ/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-18
      • 2014-05-30
      • 1970-01-01
      • 2018-07-20
      • 2013-09-11
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多