【问题标题】:Maintain equal height on resize (jQuery)在调整大小时保持相等的高度(jQuery)
【发布时间】:2010-12-02 14:59:03
【问题描述】:

我使用此代码来平衡列:

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");
 }
});
};

.. 做得不错,但是我在其中一个列中有一个手风琴菜单,它可以滑入/滑出改变列的高度,equalheight 不能很好地配合它。每次调整列大小时是否可以均衡列?

谢谢大家!

【问题讨论】:

  • 即使尝试使用 setTimeout 和 setInterval,也不起作用。 :-(

标签: jquery height equals


【解决方案1】:

好的,这很适合跨浏览器:

(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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2013-06-23
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多