2012-07-12 165 views
0

我发现了一个脚本here,用于均衡行(引导程序)中div的高度。你如何将20例加入到它计算的新高度?jQuery添加变量

这里是脚本和的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(); 
}); 

回答

2

试试下面的代码片段:

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/

+0

谢谢!那很完美。 – user1519730 2012-07-12 05:40:49