

// 获取元素距离浏览器顶部的距离
export const getElementTop = (elem: HTMLElement): number => {
  let elemTop: number = elem.offsetTop;
  let pElem: any = elem.offsetParent;
  while (pElem != null) {
    elemTop += pElem.offsetTop;
    pElem = pElem.offsetParent;
  }
  return elemTop;
}

// 获取元素距离浏览器顶部的距离
export const getElementLeft = (elem: HTMLElement): number => {
  let elemLeft = elem.offsetLeft;
  let pElem: any = elem.offsetParent;
  while (pElem != null) {
    elemLeft += pElem.offsetLeft;
    pElem = pElem.offsetParent;
  }
  return elemLeft;
}

export const getScrollTop = () => {
  return document.documentElement.scrollTop;
}

// 浏览器可视宽高
export const getWindowSize = () => {
  return {
    width: document.body.clientWidth,
    height: document.body.clientHeight,
  }
}