该Element.getBoundingClientRect()方法返回一个 DOMRect 对象,该对象提供元素大小及其相对于视口的位置信息;
用法如下: domRect = element.getBoundingClientRect();
返回元素的 left, top, right, bottom, x, y, width, and height 值;
const h3 = document.querySelector("h3");
const rect = h3.getBoundingClientRect();
const topElement = document.documentElement;
const positionTop = topElement.scrollTop (滚动的距离)+ rect.top;
const positionLeft = topElement.scrollLeft + rect.left;