我想得到另一层的 margin-top
大小和 height
的总和。
.nav1
的 margin-top 是 30px,.main
的高度是 28px
我使用这段代码:
$('.nav').css('margin-top').replace('px', '') + $('.main').outerHeight()
但我求和的结果是3028
如何计算这两个数字的总和?
最佳答案
如果您想计算 margin-top
和 margin-bottom
属性:http://api.jquery.com/outerheight/#outerHeight-includeMargin
var heightWithMargin = $('.main').outerHeight(true);
关于jquery - 使用 jQuery 获取边距和高度的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14559389/