2012-04-24 87 views
0

我正在为正在制作的网站构建响应日历。日历使用下面的JavaScript缩小罚款,以保持divs设置为相同的高度。将div缩放到相等的高度,需要的最大高度

$(function(){ 
    var equalHeight = function() { 
     $(".calBody").each(function(){ 
      var maxHeight = 0; 
      $(this).children(".calBlock") 
       .each(function() { maxHeight = Math.max(maxHeight, $(this).height()); }) 
       .css('min-height',maxHeight); 
     }); 
    } 

    equalHeight(); 

    $(window).resize(function(){equalHeight()}); 
}); 

这使列不错,甚至从一开始,当它被缩小,但是当你开始缩手了它不断的div从当他们在他们的最高的最大高度。

任何让他们扩大规模的想法只能达到最高div缩放比例所需的高度吗?

这里是它的一个的jsfiddle在行动:jsfiddle.net/7n4VH/1

+0

你能否显示一些标记?更好的将是一个jsFiddle – 2012-04-24 15:11:49

+0

这是我能做的最好的,因为它是动态生成的,不想修改一堆代码来添加空格和制表符:http://jsfiddle.net/7n4VH/1/ – projectxmatt 2012-04-24 15:18:10

回答

1

尝试让.calBlock的儿童.height()代替。例如:

.each(function() { maxHeight = Math.max(maxHeight, $(this).children('.events:first').height()); }) 
.css('min-height',maxHeight+30); 
+0

完美!谢谢! – projectxmatt 2012-04-24 16:46:31