下面的代碼應該找到最大列(.border)的高度,並調整.container div中找到的任何其他列的高度等於它。不幸的是,我一直無法獲得此代碼的工作,所以我希望有人比我更能幫助我。在窗口調整大小重新計算等高度列
還值得一提的是,每當窗口大小調整後,應重新計算列高度並重新調整列大小。
<script type="text/javascript">
$(document).ready(function(){
//Bind the window onresize event
$(window).bind('resize', resizeWindow);
//Call resizeWindow() function immediately to intiially set elements
resizeWindow();
});
function resizeWindow(){
//Find all the container parent objects
$('.container').each(function(){
//Initialize the height variable
var maxHeight = 0;
//Cache the jQuery object for faster DOM access and performance
var $borders = $(this).find('.border');
//Find all the border child elements within this specific container
$borders.each(function(){
//Get current element's height
var thisHeight = $(this).height();
//Check if the current height is greater than the max height thus far
//If so, change max height to this height
if (thisHeight>maxHeight) maxHeight = thisHeight;
});
//Now that we have the maximum height of the elements,
//set that height for all the .border child elements inside the parent element
$borders.height(maxHeight);
});
}
</script>
<div class="container">
<a href="#" class="border">
<div class="column">
<div class="content">asdf</div>
</div>
</a>
<a href="#" class="border">
<div class="column">
<div class="content">asdf</div>
</div>
</a>
</div>
是否有任何理由,CSS'columns'不會做? – 2013-03-04 23:18:54
@Kolink有。總結它不是一個選項。 – Rich 2013-03-04 23:21:32