开发者

Jquery: code works, but is ugly

var ProdWidth = Math.abs(parseInt(Product.css('width')))
+ Math.abs(parseInt(Product.css('marginLeft')))
+ Math.abs(parseInt(Product.css('marginRight')))
+ Math.abs(parseInt(Product.css('paddingLeft')))
+ Math.abs(parseInt(Product.css('paddingRight')));

This works for coming up with the total width of an element including padding and margins, but its stupid. How should I b开发者_运维技巧e doing it?


Check out the outerWidth() property. It gets the width of the element and its padding, border, etc.

Setting its first argument to true will include the margins.

var ProdWidth = Product.outerWidth(true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜