jQuery中height、innerheight和outerheight的区别

1.jQuery中的height()、innerheight()、outerheight()

1.1 获取/设置对应选择器标签的高度  
    $("div").height(); 获取
    $("div").height(100);  //设置
    当然你也可以使用function设置对应标签的高度

     $("button").click(function(){
//index为当前元素的索引 height是原始高度   
$("div").height(function(index,height){
    return height+10;
    });
  });



1.2 innerHeight这个很简单 直接获取就可以了
$("div").innerHeight();

1.3 outerHeight(option) option是bool值 默认是false
 使用和你简单 :div.outerHeight()  div.outerHeight(true)

另外的三个宽度同理类比就可以了


总结:参考上面的盒子模型图,height是获取content的高度, innerHeight = content的高度 + padding-top + padding=bottom 

outHeight参数为false的话  outHeight = 上面的innerHeight + border-top + border-bottom 

为true:outHeight = innerHeight +  border-top + border-bottom + margin-top + margin-bottom

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值