开发者

Jquery: code works, but is ugly

开发者 https://www.devze.com 2023-02-28 12:41 出处:网络
var ProdWidth = Math.abs(parseInt(Product.css(\'width\'))) + Math.abs(parseInt(Product.css(\'marginLeft\')))
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

精彩评论

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