相关网址:http://www.tmla.org/new_site/
所以我有这个自定义函数,它找到所有3列的高度,然后在最短列的最后一个窗口小部件上添加高度。在初始加载时,左侧列变长。如果你重新加载页面,它工作正常。任何人都可以对此有所了解吗?函数调用和函数代码如下:
<script>
jQuery(document).ready(function(){
//EVEN OUT COLUMNS
jQuery(".main_equal2").equalHeights();
jQuery(".main_equal3").equalHeights2();
jQuery(".main_equal4").equalHeights3();
});
</script>
(function($) {
$.fn.equalHeights = function(minHeight, maxHeight) {
column1 = 0;
column2 = 0;
column3 = 0;
//FIND THE TOTAL HEIGHT OF EACH COLUMN BY ADDING UP EACH WIDGET, SORTING BY UNIQUE COLUMN CLASS
this.each(function() {
if($(this).hasClass('column1')) {
column1 = column1 + $(this).height();
} else if($(this).hasClass('column2')) {
column2 = column2 + $(this).height();
} else if($(this).hasClass('column3')) {
column3 = column3 + $(this).height();
}
});
//alert(column1);
//alert(column2);
//alert(column3);
//FIND THE TALLEST COLUMN
tallest = Math.max(column1, column2, column3);
//alert(tallest);
//SIMPLE MATH TO DETERMINE HOW MUCH HEIGHT TO MAKE THE LAST WIDGET OF EACH COLUMN SO THEY LINE UP NICE AND NEAT
column1 = tallest - column1 + $('#left_sidebar .widget').last().height();
column2 = tallest - column2 + $('#center_sidebar .widget').last().height();
column3 = tallest - column3 + $('#right_sidebar .widget').last().height();
//alert('Add how much to Column 1: ' + column1);
//alert('Add how much to Column 2: ' + column2);
//alert('Add how much to Column 3: ' + column3);
//alert('Left' + $('#left_sidebar .widget').last().css('height'));
//alert('Center' + $('#center_sidebar .widget').last().css('height'));
//alert('Right' + $('#right_sidebar .widget').last().css('height'));
if(column1 != '0px') {
$('#left_sidebar .widget').last().css('height', column1 + 'px');
}
if(column2 != '0px') {
$('#center_sidebar .widget').last().css('height', column2 + 'px');
}
if(column3 != '0px') {
$('#right_sidebar .widget').last().css('height', column3 + 'px');
}
}
})(jQuery);