JS获得元素相对位置坐标getBoundingClientRect()

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

1.语法:这个方法没有参数。

rectObject = object.getBoundingClientRect();
function inputKeydown(e){
  console.log(e.target.getBoundingClientRect());//bottom:199height:19left:360right:380top:180width:20x:360y:180
}

记录一下备用:
https://www.cnblogs.com/Songyc/p/4458570.html





原文地址:https://www.cnblogs.com/xiangsj/p/8610002.html