开发者

jquery add width + padding;

开发者 https://www.devze.com 2023-01-12 10:56 出处:网络
i am trying to do var width = ($(this).width() + $(this).css(\'padding-left\') + $(this).css(\'padding-right\'));

i am trying to do var width = ($(this).width() + $(this).css('padding-left') + $(this).css('padding-right'));

do add the width to the padding, so i should end up with width = 200 + 4 + 4 = 208 instead i end up wi开发者_StackOverflowth 2004px4px;

how can i force it to add them to get 208?


Why dont you use outerWidth property instead. http://api.jquery.com/outerWidth/


Use parseInt

var width = $(this).width();
var paddingLeft  = parseInt($(this).css('padding-left' ), 10);
var paddingRight = parseInt($(this).css('padding-right'), 10);

var paddedWidth = width + paddingLeft + paddingRight;

Or better use the jSizes plugin as mentioned in this answer.

0

精彩评论

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

关注公众号