首页 > 其他 > 详细

01-offsetWidth和offsetHeight

时间:2017-03-21 15:31:51      阅读:258      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        div {
            width: 100px;
            height: 100px;
            padding: 10px;
            border: 10px solid #000;
            margin: 100px;
            background-color: pink;
        }
    </style>
</head>
<body>

    <div class="box"></div>

<script>
    
    var div = document.getElementsByTagName("div")[0];

    //offsetHeight和offsetWidth: 可以检测盒子的宽高。
    //包括宽高本身,padding,border。不包括margin

    //offsetHeight = height+padding+border;(不加margin)
    //offsetWidth = width+padding+border;(不加margin)

    console.log(div.offsetHeight);
    console.log(typeof div.offsetHeight);   //number

</script>


</body>
</html>

  

01-offsetWidth和offsetHeight

原文:http://www.cnblogs.com/sj1988/p/6594085.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!