我使用此代码来均衡列:
jQuery.fn.equalHeight=function() {
var maxHeight=0;
this.each(function(){
if (this.offsetHeight>maxHeight) {maxHeight=this.offsetHeight;}
});
this.each(function(){
$(this).height(maxHeight + "px");
if (this.offsetHeight>maxHeight) {
$(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");
}
});
};
..做得不错,但我在其中一个列中有一个 Accordion 菜单,可以滑入/滑出改变列的高度,equalheight 并不能很好地发挥作用。每次调整大小时是否可以均衡列?
谢谢!
最佳答案
好的,这在跨浏览器上效果很好:
(function($) {
$.fn.equalHeight = function(){
var height = 0,
reset = $.browser.msie ? "1%" : "auto";
return this
.css("height", reset)
.each(function() {
height = Math.max(height, this.offsetHeight);
})
.css("height", height)
.each(function() {
var h = this.offsetHeight;
if (h > height) {
$(this).css("height", height - (h - height));
};
});
};
})(jQuery);
关于jquery - 调整大小时保持相同高度 (jQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1497556/