width
- 参数:
- number: 宽度大小
- string: 带单位的宽度大小
- 做用:
- 获取jQ对象content宽度
- 设置jQ对象content宽度
- code:
.wrapper {
position: absolute;
width: 200px;
height: 200px;
background-color: orange;
}
复制代码
<div class="wrapper"></div>
复制代码
console.log($('.wrapper').width());
$('.wrapper').width(100);
$('.wrapper').width('100px');
复制代码
innerWidth
- 做用:
- 获取jQ对象content + padding宽度
- code:
.wrapper {
width: 200px;
height: 200px;
padding: 10px;
background-color: orange;
}
复制代码
<div class="wrapper"></div>
复制代码
console.log($('.wrapper').innerWidthWidth());
复制代码
outWidth
- 参数:
- 做用:
- 获取jQ对象content + padding + border宽度
- 说明:
- 当传入参数为true时,返回宽度为content + padding + border + margin的总和
- code:
.wrapper {
width: 200px;
height: 200px;
padding: 10px;
border: 5px solid red;
margin: 10px;
background-color: orange;
}
复制代码
<div class="wrapper"></div>
复制代码
console.log($('.wrapper').outerWidth())
console.log($('.wrapper').outerWidth(true))
复制代码