jquery等高插件添加边距

标签 jquery jquery-plugins

如何添加下面的代码来确定 DIV 是否有任何 margin-top/margin-bottom?我目前的情况是,我有 2 列(DIV),其中 1 列有顶部边距,另一列没有,这会导致列无法正确对齐。

抱歉,代码已被缩小,我丢失了原始代码。

$.fn.equalHeight = function (a) {
    var b = {
        delay: 100,
        minusHeight: 0
    };
    var a = $.extend(b, a);
    var c = 0;
    var d = 0;
    var e = $(this);
    setTimeout(function () {
        e.each(function () {
            c = $(this).outerHeight();
            d = c > d ? c : d
        });
        return e.each(function () {
            var b = $(this);
            var c = d - (b.outerHeight() - b.height()) - a.minusHeight;
            var e = jQuery.browser.msie && jQuery.browser.version < 7 ? "height" : "min-height";
            b.css(e, c + "px")
        })
    }, a.delay)
};

最佳答案

您应该将 true 作为参数添加到 .outerHeight()以便在计算中包含边距。

但是您的代码还有另一个问题。您无法因超时而返回任何内容,并且您似乎已将返回代码放在那里。

这意味着您正在破坏 jQuery 链接系统..

你的代码可能应该是

$.fn.equalHeight = function(a) {
    var b = {
        delay: 100,
        minusHeight: 0
    };
    var a = $.extend(b, a);
    var c = 0;
    var d = 0;

    this.each(function() {
        c = $(this).outerHeight(true);
        d = c > d ? c : d;
    });
    return this.each(function() {
        var b = $(this);
        var c = d - (b.outerHeight(true) - b.height()) - a.minusHeight;
        var e = (jQuery.browser.msie && jQuery.browser.version < 7) ? "height" : "min-height";
        setTimeout( function(){
            b.css(e, c + "px");
        }, a.delay);
    });
};

演示地址:http://jsfiddle.net/gaby/DXHtk/

关于jquery等高插件添加边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7877625/

相关文章:

javascript - 如何用jquery加载图片?

javascript - 显示消息而不重新加载 html 页面

jquery - 制作一个依赖于其他 jQuery 扩展的 jQuery 扩展可以吗?

javascript - 从异步加载的外部脚本中使用 jQuery 插件

javascript - jqGrid 中的自定义客户端聚合

javascript - jQuery 问题无法检索或设置属性, 'undefined'

jquery - 对不包含另一个范围的范围进行特殊搜索

php - 如何在ajax过程中显示加载动画和禁用按钮

javascript - 使表格行在 Jquery DataTables 的所有页面上都可点击

javascript - 如何销毁 PDFJS 对象?