jquery等高插件添加边距
我如何添加到下面的代码来计算 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)
};
How would I add to the code below to work out if a DIV has any margin-top/margin-bottom? The situation I have at the moment is that I have 2 columns (DIV's) 1 have a margin-top and the other doesn't which causes the columns not to line up correctly.
Sorry the code has been minified and I have lost the original.
$.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)
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将
true
作为参数添加到.outerHeight()
以便在计算中包含边距。但是你的代码还有另一个问题..你不能从超时中返回任何内容,并且你似乎已经将返回代码放在那里了..
这意味着你正在破坏 jQuery 链接系统..
你的代码可能应该是
演示 http://jsfiddle.net/gaby/DXHtk/
You should add
true
as a parameter to.outerHeight()
so that it includes the margin in the calculations.But there is another issue with your code.. You cannot return anything from a timeout, and you seem to have placed your return code in there..
This means you are breaking the jQuery chaining system..
Your code should probably be
Demo at http://jsfiddle.net/gaby/DXHtk/
您可以使用 jQuery 的
css()
函数检查 div 的边距。不幸的是,不支持像margin
这样的简写 css 属性,您必须以css('marginTop')
、css('marginBottom ')
等等。然后,您可以有条件地修改每个div
,使其对齐。You can check the div for margins using the
css()
function of jQuery. Unfortunately shorthand css properties likemargin
aren't supported and you'll have to do it in the form ofcss('marginTop')
,css('marginBottom')
and so on. You can then conditionally modify eachdiv
so that it will line up.