概念:

getBoundingClientRect用于获取某个元素相对于视窗的位置集合。集合中有top, right, bottom, left等属性。

语法:

这个方法没有参数

  1. var reactObject = node.getBoundingClientRect();

返回值:

  1. //返回值类型
  2. console.log(reactObject.top); //元素上边到视图上边的距离
  3. console.log(reactObject.right); //元素右边到视图左边的距离
  4. console.log(reactObject.bottom); //元素下边到视图上边的距离
  5. console.log(reactObject.left); //元素左边到视图左边的距离

image.png

作用:

这个属性在ie5就开始支持,能做什么呢? 在淘宝 京东 支付宝 里面可见的效果 。吸顶导航条。