/**
 * 修改页面标题
 */
export function changeTitle(title: string): void {
  const iframe = document.createElement('iframe');

  iframe.style.cssText = 'visibility: hidden;width: 1px;height: 1px;';
  iframe.src = '../../changeTitle.html';
  iframe.onload = function(): void {
    setTimeout(function(): void {
      document.body.removeChild(iframe);
    }, 100);
  };
  document.title = title;
  document.body.appendChild(iframe);
}

/**
 * 获取父元素在滚动条的位置
 */
export function getElemPos(elem: HTMLElement): { x: number, y: number } {
  const pos = { top: 0, left: 0 };
  let temp: any = elem;
  if (temp.offsetParent) {
    while (temp.offsetParent) {
      pos.top += temp.offsetTop;
      pos.left += temp.offsetLeft;
      temp = temp.offsetParent;
    }
  } else if (temp.x) {
    pos.left += temp.x;
  } else if (temp.x) {
    pos.top += temp.y;
  }
  return { x: pos.left, y: pos.top };
}