目录
一.offset家族
1.1offsetparent
表示该元素的父盒子而且必须还有定位
如图所示:求红色盒子的offsetpare
先判断红色盒子是否为fix定位,是fixed定位offsetparent为body
如若不是,看上一级盒子是否有定位,有定位则,上一级盒子为offsetparent
body元素的
1.2offsetwidth和offsetheight
offsetwidth=width+左右边框+左右padding
offsetheight=height+上下边框+上下padding
与style相比
.box{
background-color: black;
width: 100px;
height: 100px;
padding: 50px;
margin: 10px;
}
</style>
</head>
<body>
<div class="box">
</div>
<script>
var box=document.querySelector('.box');
console.log(box.offsetWidth,box.style.width);
</script>
style只能读取行类设置的属性
1.3offsetTop和offsetleft
offsetTop当前元素上边款到offsetParent元素上边框的距离
offsetleft当前元素上边框到offsetParent 元素上边框的距离
二.client客户端大小
指的是元素内容到内边距占据空间的大小
2.1clientwidth
clientwidth=width+左右padding
2.2clientHeight
clientHeight=width+上下padding
2.3clientleft
左边框大小clienttop上边框大小
2.4其他注意事项
1.所有的client属性都是只读的和offset属性一样
2.如果给元素设置display:none则客户端属性client都为0
3.尽量避免重复访问这些属性
三.关于scroll的概念
1.scrollHeight:表示的总高度,包括由于溢出而无法在网页的不可见部分
2.无滚动条的情况下,scrollheight和clientheight属性结果是相等的
3.scroll是可读写的,并不是可读的