import isHTMLElement from './isHTMLElement';

/**
 * 获取页面滚动位置
 * @param {HTMLElement} element
 * @returns {{scrollLeft: number, scrollTop: number}}
 */
function getScrollPosition(element) {
  if (isHTMLElement(element)) {
    return {
      scrollLeft: element.scrollLeft,
      scrollTop: element.scrollTop
    };
  }

  var de = document.documentElement;
  var db = document.body;
  return {
    scrollLeft: de.scrollLeft || db.scrollLeft,
    scrollTop: de.scrollTop || db.scrollTop
  };
}

export default getScrollPosition;
